Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
631 views140 pages

Dms All Unit Imp Questions

This document is a question paper with solutions for the Database Management System subject for second-year Computer Engineering students at Rajarshi Shahu College of Engineering. It includes various questions covering topics such as advantages of DBMS, data models, and the overall structure of DBMS, along with their respective answers. The document serves as a study guide for students preparing for their examinations.

Uploaded by

jayeshaher66
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
631 views140 pages

Dms All Unit Imp Questions

This document is a question paper with solutions for the Database Management System subject for second-year Computer Engineering students at Rajarshi Shahu College of Engineering. It includes various questions covering topics such as advantages of DBMS, data models, and the overall structure of DBMS, along with their respective answers. The document serves as a study guide for students preparing for their examinations.

Uploaded by

jayeshaher66
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 140

Jaywant Shikshan Prasarak Mandal’s

RAJARSHI SHAHU COLLEGE OF ENGINEERING’s


POLYTECHNIC
S.No.80, Pune-Mumbai Bypass Highway, Tathawade Campus, Pune.

Approved By AICTE & Govt. of Maharashtra, Affilated to MSBTE


NBA ACCREDITED

DTE Code – 6141 MSBTE Inst. Code - 1620

“MASTER SOLUTIONS”

(MSBTE Question Paper with Solution as per K Scheme)

Class – Second Year Computer Engineering

Semester – CO3K

Subject: Database Management System

Subject Code – 313302

DEPARTMENT OF COMPUTER ENGINEERING


RSCOEP COMPUTER ENGINEERING MRS.S.S.GHULE
JSPM’s
RAJARSHI SHAHU COLLEGE OF ENGINEERING,
POLYTECHNIC
Department of Computer Engineering
Academic Year: 2024-25

UNIT-1 (12 Marks)


MSBTE Question bank & Answer

Sr.No. Question Year Marks


1 List any two advantages of typical file processing system. W-18 2
Ans Disadvantages of file processing system 1. Data redundancy and any 4
inconsistency 2. Difficulty in accessing data 3. Data isolation 4. Integrity disadvantag
problems 5. Atomicity problems es
– 1/2 Mark
each
disadvantag
e
2 Define i) data abstraction, ii) data redundancy. W-18 2

Ans 1. Data Abstraction : 1 mark Data


Many end users are not computer trained so it is needed to hide complex Abstraction
data structuresfrom them. description
Hiding complexity of data structures from end user through different levels 1
is knownas data abstraction.It has 3 levels : mark Data
a. Physical level b. logical level c. view level 2. Data redundancy : Redundancy
The repetition of information is known as redundancy .This description
redundancy leads to higher storage and access cost. It may lead to
data inconsistency, that is different copies of the same data may
have different values.

3 Distinguish between network model and hierarchical model (any 4 points). W-18 4
W-19

W-23
S-24

2
RSCOEP COMPUTER ENGINEERING DEPARTMENT MRS.S.S.GHULE
Ans

1 Define : (i) Instance (ii) Schema S-19 2


Define the following : i) Instance ii) Schema W-23 2
S-24
ANS (i) Instance: The data stored in database at a particular moment of time is 1 M for each
called instance of database. (ii) Schema: Design of a database is called the Definition
schema. Schema is of three types: Physical schema, logical schema and
view schema.
2 State any two E.F. Codd’s rule for RDBMS. S-19 2
State any Four E.F. Codd’s rule for RDBMS. S-23 2
W-22 4
ANS 1. The Guaranteed Access rule: Each item of data in an RDBMS is

2. guaranteed to be logically accessible by resorting to a combination oftable


name, primary key value, and column name.

3. The Systematic Treatment of Null Values rule: Null values(distinct from


an empty character string or a string of blank charactersand distinct from
zero or any other number) are supported in a fullyrelational DBMS for
representing missing

4. The Dynamic Online Catalog Based on the Relational Model rule:The


database description is represented at the logical level in the sameway as
ordinary data, so that authorized users can apply the samerelational database.

5. The Comprehensive Data Sublanguage rule: A relational systemmay


support several languages and various modes of terminal for datadefinition,
view definition, data manipulation etc.

6. The View Updating rule: All views of the data which aretheoretically
updatable must be updatable in practice by the DBMS.

3
RSCOEP COMPUTER ENGINEERING DEPARTMENT MRS.S.S.GHULE
7. The High-level Insert, Update, and Delete rule: The capability ofhandling
a base relation or a derived relation as a single database toperform all DML
operations.

8. The Physical Data Independence rule: Application programs andterminal


activities remain logically unchanged whenever any changesare made in
either storage representations or access methods.

9. The Logical Data Independence rule: Application programs andterminal


activities remain logically unchanged when informationpreserving changes
of any kind are made to the base tables.

10. The Integrity Independence rule: Integrity constraints must bedefinable


in the RDBMS sub-language and stored in the system

catalogue and not within individual application programs.

11. The Distribution Independence rule: An RDBMS has


distributionindependence. Distribution independence implies that users
should not have to be aware of whether a database is distributed.

12. The No subversion rule: If the database has any means of handlinga
single record at a time that low-level language must not be able avoidthe
integrity rules which are expressed in a higher-level language thathandles
multiple records at a time.

3 List any four advantages of DBMS. S-19 2

Ans Controlling Redundancy ( ½ M for


any
advantage)

and Recovery

4 Explain overall structure of DBMS with the help of diagram S-19 4


Explain overall structure of DBMS with the help of diagram S-24 4
Draw the overall architecture of DBMS. Explain storage manager and W-22 6
query processor components.
Ans Components of DBMS structure are classified in 3 categories as: 2 M for
1. Query processor : correct

4
RSCOEP COMPUTER ENGINEERING DEPARTMENT MRS.S.S.GHULE
Embedded DML pre compiler: It converts DML statements embedded in diagram, 2
application. M
Program to normal procedural calls in host language. for correct
DML Compiler: It translates DML statements of high level language explanation
into low level instruction that a query evaluation engine understands.
DDL interpreter: It interprets DDL statements and records them in a
set of tables containing metadata.
Query evaluation Engine: It executes low level instructions generated
by DML compiler and issued by query processor to select efficient ways
to execute query.
DDL interpreter. It has following components
2. Storage Manager Components :
Transaction manager: It ensures that the database remains in
consistent state despite of the system failure and that concurrent
transaction execution proceeds without conflicting.
File Manager: It manages the allocation of space on disk storage and
data structures used to represent information stored on disk
Buffer Manager: It is responsible for fetching data from disk storage
into main memory and deciding what data to cache memory.
3. Disk storage :
Data files: It stores the database.
Data Dictionary: It stores metadata that hold particular values.
Indices: Provide fast access to data items that hold particular values.
Statistical data: It stores statistical information about the data in the
database.

5 State the difference between Relational and Hierarchical model S-19 4

5
RSCOEP COMPUTER ENGINEERING DEPARTMENT MRS.S.S.GHULE
Ans Any 4
differences :
1M each

1 State any two advantages of DBMS over file processing system. W-19 2
Explain advantages of DBMS over file processing system. S-22 4
Ans State any two advantages of DBMS over file processing system. Any two
Advantages of DBMS over file processing system: advanta
ges 1M
each

2 Draw three level architecture of DBMS W-19 2


Ans Correct
diagram
2M

1 Define data model. List its types. S-22 2

6
RSCOEP COMPUTER ENGINEERING DEPARTMENT MRS.S.S.GHULE
Ans

2 With neat diagram explain three level architecture of database system. S-22 4
Explain three level architecture of Database system. W-22 4
Ans The three levels present in this architecture are Physical level, Conceptual
level and External level.

The details of these levels are as follows −

Physical Level
This is the lowest level in the three level architecture. It is also known as
the internal level. The physical level describes how data is actually stored
in the database. In the lowest level, this data is stored in the external hard
drives in the form of bits and at a little high level, it can be said that the
data is stored in files and folders. The physical level also discusses
compression and encryption techniques.

Conceptual Level
The conceptual level is at a higher level than the physical level. It is also
known as the logical level. It describes how the database appears to the

7
RSCOEP COMPUTER ENGINEERING DEPARTMENT MRS.S.S.GHULE
users conceptually and the relationships between various data tables. The
conceptual level does not care for how the data in the database is actually
stored.

External Level
This is the highest level in the three level architecture and closest to the
user. It is also known as the view level. The external level only shows the
relevant database content to the users in the form of views and hides the
rest of the data. So different users can see the database as a different view
as per their individual requirement

1 Define i) Data Abstraction ii) Instance W-22 2


Ans i) Data Abstraction: Each correct
Hiding complexity of data structures from end user through different levels definition:
is known as data abstraction. 1M
Many end users are not computer trained so it is needed to hide complex
datastructures from them.
It has 3 levels :
a. Physical level
b. logical level
c. view level
ii) Instance:
The data stored in database at a particular moment of time is called
instance of database.
Example:
Let’s say a table teacher in our database whose name is School, suppose
the table has50 records so the instance of the database has 50 records for
now and tomorrow we
are going to add another fifty records so tomorrow the instance have total
100 records.This is called an instance.

1 Define the following terms 1)Database (2)DBMS S-23 2


Ans i) Database: Database is collection of data, which is organized in such a Definition
way thatit can be easily accessed, managed or updated. 1M each
ii) DBMS: Database Management System is software that used to manage,
storage, access and security of data.
OR
DBMS: Database management system is a large software package that
controls thespecification, organization, storage, retrieval and update of data
in a database.

1 Enlist any two Applications of DBMS W-23 2

Ans Applications of DBMS Any two


1. E-commerce applications
2. Banking 1M each
3. Airline reservation systems
4. Hospital information systems
8
RSCOEP COMPUTER ENGINEERING DEPARTMENT MRS.S.S.GHULE
5. Human resource management
6. Social media
7. Research
8. Railway Reservation System
9. Library Management System
10. Education Sector
11. Credit card exchanges
12. Broadcast communications
13. Account
14. Online Shopping
15. Manufacturing
16. Healthcare
3 State advantages of DBMS over file processing system. (Any four) W-23 4
Ans 1. Data redundancy and inconsistency: Redundancy is the concept of Correct
repetition of datai.e. each data may have more than a single copy. The file explanation
system cannot control theredundancy of data as each user defines and for any 4
maintains the needed files for a specificapplication to run. There may be a advantages
possibility that two users are maintaining the dataof the same file for 1 M each
different applications. Hence changes made by one user do notreflect in files
used by second users, which leads to inconsistency of data. Whereas DBMS
controls redundancy by maintaining a single repository of data that is
definedonce and is accessed by many users. As there is no or less
redundancy, data remainsconsistent.
2. Data sharing: The file system does not allow sharing of data or sharing is
too complex. Whereas in DBMS, data can be shared easily due to a
centralized system.
3. Data concurrency: Concurrent access to data means more than one user is
accessing the same data at the same time. Anomalies occur when changes
made by one user get lost because of changes made by another user. The file
system does not provide any
procedure to stop anomalies. Whereas DBMS provides a locking system to
stop anomalies to occur.
4. Data searching: For every search operation performed on the file system,
a different application program has to be written. While DBMS provides
inbuilt searching operations. The user only has to write a small query to
retrieve data from the database.
5. Data integrity: There may be cases when some constraints need to be
applied to the data before inserting it into the database. The file system does
not provide any procedure to check these constraints automatically. Whereas
DBMS maintains data integrity by enforcing user-defined constraints on
data by itself.
6. System crashing: In some cases, systems might have crashed due to
various reasons. It is a bane in the case of file systems because once the
system crashes, there will be no recovery of the data that’s been lost. A
DBMS will have the recovery manager which retrieves the data making it
another advantage over file systems.
7. Data security: A file system provides a password mechanism to protect
the database but how long can the password be protected? No one can
guarantee that. This doesn’t happen in the case of DBMS. DBMS has

9
RSCOEP COMPUTER ENGINEERING DEPARTMENT MRS.S.S.GHULE
specialized features that help provide shielding to its data. 8. Backup: It
creates a backup subsystem to restore the data if required.
9. Interfaces: It provides different multiple user interfaces like graphical user
interface and application program interface. 10. Easy Maintenance: It is
easily maintainable due to its centralized nature

1 List disadvantages of typical file processing system. S-24 2


Ans Slow access time
Presence of redundant data
Inconsistent Data
Data Integrity Problems
Difficulty in recovery of corrupt data
Lack of Atomicity
Problem in Concurrent Access
Unauthorized Access
Define S-24 2
2 I) data abstraction
II) Data Redundancy
Ans 1. Data Abstraction : 1M for each
Many end users are not computer trained so it is needed to hide complex
data structures from them.Hiding complexity of data structures from end Correct
user through different levels is knownas data abstraction.
It has 3 levels : Definition
a. Physical level b. logical level c. view level 2. Data redundancy : The
repetition of information is known as redundancy .This redundancy leads to
higher storage and access cost. It may lead to data inconsistency, that is
different copies of the same data may have different values

10
RSCOEP COMPUTER ENGINEERING DEPARTMENT MRS.S.S.GHULE
JSPM’s
RAJARSHI SHAHU COLLEGE OF ENGINEERING,
POLYTECHNIC
Department of Computer Engineering
Academic Year: 2024-25

UNIT-2 ( 12 Marks)
MSBTE Question bank

Sr.No. Question Year Marks


1 Define the term : i) Candidate key ii) Primary key W-18 2
S-23
ans Candidate key: In a relation, there may be a primary key or may 1 mark
not, but there may be a key or combination of keys which uniquely Candidate key
identify the record. Such a key is called as Candidate key. OR A 1 mark
candidate key is a column, or set of columns, in a table that can Primary Key
uniquely identify any database record without referring to any
other data. The candidate key can be simple (having only one
attribute) or composite as well. For Example, {STUD_NO,
COURSE_NO} is a composite candidate key for relation
STUDENT_COURSE.
Primary key: A key which is selected by the designer to uniquely
identify the entity is called as Primary key. A primary key cannot
contain duplicate values and it can never contain null values inside
it. Example, RollNo attribute is a primary key for Relation Student
2 Define normalization, list its types. W-18 2
S-19
W-22
S-24
ans Normalization:
Normalization can be defined as process of
decomposition/division of database tables to
avoid the data redundancy.
Types of Normalization:
1. 1NF
2. 2NF
3. 3NF
4. BCN
3 State and explain 1NF and 2NF with example. W-18 4
S-23 6

S-24 4

11
RSCOEP COMPUTER ENGINEERING DEPARTMENT MRS.S.S.GHULE
ans First Normal Form (1NF):
A relation R is said to be in first normal form (1NF) if the domain
of all attributes of R
are atomic.
OR
A table is in the first normal form if it contains no repeating
elements groups. Example:
Supplier(sno,sname,location,pno,qty)

4 Draw an E-R diagram of library management system considering W-18 6


issue and return, fine calculation facility, also show primary key,
weak entity and strong entity.
ans

1 State and explain 2NF with example S-19 4


Define Normalization. Explain 2NF with example. S-22 4
ans A table is said to be in 2NF if both the following conditions hold:
 Table is in 1NF (First normal form)  No non-prime attribute is
dependent on the proper subset of any candidate key of table.  San
attribute that is not part of any candidate key is known as non- prime
attribute.  Example: Suppose a school wants to store the data of
teachers and the subjects they teach. They create a table that looks
like this: Since a teacher can teach more than one subjects, the
table can have multiple rows for a same teacher.

12
RSCOEP COMPUTER ENGINEERING DEPARTMENT MRS.S.S.GHULE
CandidateKeys:{teacher_id,subject}
Non-prime attribute: teacher_age The table is in 1 NF because
each
attribute has atomic values. However, it is not in 2NF because
nonprime attribute teacher_age is dependent on teacher_id alone
which is a proper subset of candidate key. This violates the rule
for 2NF as the rule says “no non-prime attribute is dependent on
the proper subset of any candidate key of the table “To make the
table complies with 2NF we can break it in two tables like this:
teacher details tab
A table is said to be in 2NF if both the following conditions hold:
 Table is in 1NF (First normal form)  No non-prime attribute is
dependent on the proper subset of any candidate key of table.  San
attribute that is not part of any candidate key is known as non- prime
attribute.  Example: Suppose a school wants to store the data of
teachers and the subjects they teach. They create a table that looks
like this: Since a teacher can teach more than one subjects, the
table can have multiple rows for a same teacher.

CandidateKeys:{teacher_id,subject}
Non-prime attribute: teacher_age The table is in 1 NF because
each attribute has atomic values. However, it is not in 2NF because
nonprime attribute teacher_age is dependent on teacher_id alone
which is a proper subset of candidate key. This violates the rule for
2NF as the rule says “no non-prime attribute is dependent on the
proper subset of any
candidate key of the table “To make the table complies with 2NF
we
can break it in two tables like this: teacher_subject Table
13
RSCOEP COMPUTER ENGINEERING DEPARTMENT MRS.S.S.GHULE
2 Draw ER diagram for library management system considering S-19 6
issue and return, fine collection facility. Consider appropriate
entities.
ans

1 Define table and field. W-19 2


ans Table: A table is a collection of related data held in table format. Each
It is a set of data elements using a model of vertical columns and definitio
horizontal rows. n 1M
Field: Each table contains field which is a data structure, used to
hold the data. It can also be termed as attribute.
2 Define primary key and foreign key. W-19 2
ans Primary key ;is an attribute or set of attributes used to identify an Each
entity from an entity set. All the values of a primary key should be definitio
unique and null values are not allowed. n 1M
Foreign key is an attribute of an entity which is the primary key
of
another entity. It is used to show relation between entities. The
table containing foreign key is called the child table.
3 State and explain 3NF with example. W-19 4

14
RSCOEP COMPUTER ENGINEERING DEPARTMENT MRS.S.S.GHULE
ans 3NF: Explana
An entity is said to be in the third normal form when, tion 2M
1) It satisfies the criteria to be in the second normal form. Any
2) There exists no transitive functional dependency. (Transitive example
functional dependency can be explained with the relationship link 2M
between three tables. If table A is functionally dependent on B,
and B is functionally dependent on C then C is transitively
dependent on A).
Let us consider the Schema given:
(Supplier_no,SupplierName,Supplier_city,Order_no,Order_quant
ity,
Order_amount,Product_code,Product name,rate)
Step 1.To convert it into 2NF, We have to decompose the given
table into two tables with fully functional dependencies and
establishing a referential integrity constraint relationship among
the two tables.Table2: Supplier Details
(Supplier_no,Supplier_name,Supplier_city)
Table 3:Order Details
(Order_no,Orderquantity,Order_amount,Supplier_no
Product_code,
product_name,rate)
Now the above two tables are in 2NF
Step 2: To convert the above tables in 3NF, we have to
decomposehem in three tables satisfying the transitive
dependencies
property.
Table 4: Supplier Details
(Supplier_no,Supplier_name,Supplier_city)
Table 5: Product Details:
(Product_code, product_name,rate)
Table 6: Order Details (or Transaction Details)
((Order_no,Supplier_no,Product_code,Order_quantity,Order_am
ount
)
Hence the above three tables are satisfying Transitive
dependencies.
Thus they are in 3NF.
4 Explain strong and weak entity set. W-19 4
ans Strong entity set: Each
An entity set that has sufficient attributes to form a primary key is entity set
called as Strong entity set. 2M
Example: Employee is a Strong entity with attributes as empid,
name,
address, salary, birthdate among which empid can be considered
as
primary key.
Weak entity set:
The entity set which does not have sufficient attributes to form a
primary key is called as Weak entity set.
A weak entity is an entity that cannot be uniquely identified by its

15
RSCOEP COMPUTER ENGINEERING DEPARTMENT MRS.S.S.GHULE
attributes alone; therefore, it must use a foreign key in conjunction
with its attributes to create a primary key. The foreign key is
typically
a primary key of an entity it is related to.
Example: Employee has "dependents" with name, birthdate, and
relationship to employee and it can be related to employee with the
help of empid, so "dependents" is a weak entity which depends on
strong entity "Employee".
5 Draw an ER diagram for library management system. (Use Books, W-19 6
Publisher & Member entities).
ans

1 State the components used in E-R diagram. S-22 2

16
RSCOEP COMPUTER ENGINEERING DEPARTMENT MRS.S.S.GHULE
ans

3 Explain. i) Candidate key ii) Foreign key S-22 4


ans Candidate key: In a relation, there may be a primary key or may
not, but there may be a key or combination of keys which uniquely
identify the record. Such a key is called as Candidate key. OR A
candidate key is a column, or set of columns, in a table that can
uniquely identify any database record without referring to any
other data. The candidate key can be simple (having only one
attribute) or composite as well. For Example, {STUD_NO,
COURSE_NO} is a composite candidate key for relation
STUDENT_COURSE
A foreign key is a column or group of columns in a relational
database table that provides a link between data in two tables. It
acts as a cross-reference between tables because it references the
primary key of another table, thereby establishing a link between
them.
4 Draw E-R diagram of Banking system considering deposite, S-22 6
withdrawal facility. Also show primary key, weak entity, strong
entity.

17
RSCOEP COMPUTER ENGINEERING DEPARTMENT MRS.S.S.GHULE
ans

1 Explain Primary and Unique key constraint with syntax. W-22 4


ans Primary key constraint:
Primary key constraint applied to any column can’t accept the
duplicate and null
values.
This constraint can be applied at the time of table creation.
Syntax for Primary Key:
CREATE TABLE <Table_Name>
(
Column1 datatype,
Column2 datatype,CONSTRAINT <Name> PRIMARY KEY
(Column name)
);
Example:
CREATE TABLE CUSTOMERS
( ID INT NOT NULL,
AGE INT NOT NULL,
ADDRESS CHAR (25),
PRIMARY KEY (ID) )
CREATE TABLE CUSTOMERS
(
ID INT NOT NULL,
NAME VARCHAR (20) NOT NULL,
AGE INT NOT NULL,
ADDRESS CHAR (25) ,
SALARY DECIMAL (18, 2),
PRIMARY KEY (ID, NAME)
);
Unique key constraint:
Unique key constraint applied to any column can’t accept the
duplicate values (only
accepts unique values).
This constraint can be applied at the time of table creation.
Syntax for Unique key:

18
RSCOEP COMPUTER ENGINEERING DEPARTMENT MRS.S.S.GHULE
CREATE TABLE <Table_Name>
(
Column1 datatype,
Column2 datatype, CONSTRAINT <Name> UNIQUE KEY
(Column name)
);
Example:
CREATE TABLE students
(
S_Id int NOT NULL,
LastName varchar (255) NOT NULL,
FirstName varchar (255),
City varchar (255),
UNIQUE (S_Id)
)
OR
CREATE TABLE students
(
S_Id int NOT NULL,
LastName varchar (255) NOT NULL,
FirstName varchar (255),
City varchar (255),
CONSTRAINT uc_studentId UNIQUE (S_Id, LastName)
)

1 Explain not null constraint with example S-23 4


ans The Not Null constraint is used to ensure that a given column of a
table is never
assigned the null value.
Example:
CREATE TABLE student
(
Rollno number(4) constraint NN NOT NULL,
Name varchar(255) ,
Marks number(3)
);
Check Constraint:
The Check constraint is used to limit the value range that can be
placed in a
column.
Example:
CREATE TABLE student
(
Rollno number(4),
Name varchar(255),
Marks number(3),
Age number(3) constraint ck CHECK (Age>=18)
);
2 Explain any four attributes with example S-23 4

19
RSCOEP COMPUTER ENGINEERING DEPARTMENT MRS.S.S.GHULE
ans 1. Simple Attribute: Simple attributes are those that cannot be
further divided into sub-attributes.
For example, roll number of a student or the employee
identification number.
2. Composite Attribute: Composite attributes are made up of two
or more simple
attributes.For example, a persons address may be a composite
attribute that is made up of
the persons street address, city, state, and zip code.
3. Single Valued Attribute: Single-valued attributes can only have
one value.
Single-valued attributes are typically used to provide a unique
identifier for an
entity and are often used in databases.
For example, a persons Social Security Number is a single-valued
attribute.
4. Multivalued Attribute: Multivalued attributes can have more
than one value.
For example, a person may have multiple email addresses or phone
numbers.
5. Stored Attribute: Values of stored attributes remain constant and
fixed for an
entity instance and also, and they help in deriving the derived
attributes.
For example, the Age attribute can be derived from the Date of
Birth attribute, and
also, the Date of birth attribute has a fixed and constant value
throughout the life
of an entity. Hence, the Date of Birth attribute is a stored attribute.
6. Derived Attribute: Derived attributes are based on other
attributes and are not
stored directly in the database.
For example: Consider a database of employees. Each employee
has a date of
birth, and we can calculate their age which can be called as derived
attribute.
3 Explain strong entity and weak entity set .draw diagram indicating S-23 6
strong and weak entity set
Explain strong and weak entity set. 4
W-19

ans Strong entity set:


Entity set that have sufficient attribute to define the primary key is
called
as strong entity sets.

single.

20
RSCOEP COMPUTER ENGINEERING DEPARTMENT MRS.S.S.GHULE
a
diamond symbol
of
an entity set
with the relationship set. Total participation may or may not exist
in the
relationship.
Example:
Student and course relation: Student entity is a strong entity
because it
consists of a primary key called student id which is enough for
accessing each
record uniquely. In the same way, the course entity contains of
course ID attribute
which is capable of uniquely accessing each row.

Weak entity set:


Entity sets that does not have sufficient attribute to define the
primary key iscalled as weak entity set.

set.
he identifying
relationship is double.
strong and a weak entity set is
represented by a doublediamond symbol.(known as identifying
relationship)

Example:
Employee is a strong entity because it has a primary key attribute
called Employee number (Employee_No) which is capable of
uniquely
identifying all the employee.Unlike Employee, Dependents is
weak entity because it does not have any primary key .

21
RSCOEP COMPUTER ENGINEERING DEPARTMENT MRS.S.S.GHULE
4 Draw an ER Diagram of Libarary management system consdiering S-23 6
publisher, member also show primary key , weak entity and strong
entity
ans

1 Define Normalization. State and explain 2NF with example. W-23 4


ans Normalization is a process of organizing the data in database to
avoid data redundancy,

22
RSCOEP COMPUTER ENGINEERING DEPARTMENT MRS.S.S.GHULE
insertion anomaly, update anomaly & deletion anomaly.
Second Normal Form (2NF):
A relation is said to be in the second normal form if it is in first
normal form and all the
non key attributes are fully functionally dependent on the primary
key.
Example

• This table is in first normal form, in that it obeys all the rules of
first normal form.
• In this table, the primary key consists of SNO.
• However, the table is not in second normal form because there
are partial
dependencies of primary keys and columns.
• In the above relation NAME, LOCATION depends on SNO and
QTY on (SNO,
PNO)
• so the table can be split up into two tables as
Supplier(SNO,SNAME,LOCATION)
and SP(SNO,PNO,QTY) and now both the tables are in second
normal form.
Supplier

23
RSCOEP COMPUTER ENGINEERING DEPARTMENT MRS.S.S.GHULE
2 Draw ER diagram for Hospital management system. (Use Entity- W-23 6
Doctor, Patient, Hospital and Medical Record). Show Primary
Key, and Foreign Key
ans Correct
entities: 2M,
correct
symbols: 2M,
Correct
relationships:
2M

3 Draw ER Diagram for hospital management system S-24 4

24
RSCOEP COMPUTER ENGINEERING DEPARTMENT MRS.S.S.GHULE
ans

25
RSCOEP COMPUTER ENGINEERING DEPARTMENT MRS.S.S.GHULE
26
RSCOEP COMPUTER ENGINEERING DEPARTMENT MRS.S.S.GHULE
JSPM’s
RAJARSHI SHAHU COLLEGE OF ENGINEERING,
POLYTECHNIC
Department of Computer Engineering
Academic Year: 2024-25

UNIT-3 ( 18 Marks)
MSBTE Question bank

Sr.No Question Year Marks


1 Enlist four aggregate functions. W-18 2
SUM() any 4
AVG() functions
MAX()
MIN()
COUNT()
2 List four DDL commands with syntax. W-18 2
DDL commands
1. 1.Create
Syntax : create table <table_name>(Column_name1 datatype1,
column_name2
Datatype2,…Column_nameN DatatypeN);
2. Drop
Syntax: drop table <table_name>;
3. Desc
Syntax: describe <table_name>;
OR
Desc <table_name>
4. Truncate
Syntax: truncate table <table_name>;
5. Alter
Syntax: Alter table <table_name> add Column_name Datatype
(size);
3 Explain any four string functions with example. W-18
S-22,
S-23

27
RSCOEP COMPUTER ENGINEERING DEPARTMENT MRS.S.S.GHULE
i) Lower(char)-
Returns the input string with all letters in lower case.
Example: SQL>Select lower (‘RAJESH’) from dual;
Output: rajesh
ii) Upper(char)-
Returns the input string with all letters in upper case.
Example: SQL>Select upper (‘rajesh’) from dual;
Output: RAJESH
iii) Ltrim(char,set)-
It removes or trims from left of character string
. Example: SQL>Select Ltrim(‘university’,’univ’) from dual;
Output: ersity
iv) Rtrim(char,set)-
It removes or trims from right of character string.
Example: SQL>Select Rtrim(‘university’,’sity’) from dual;
Output: univer
v) Length(char)-
It returns length of character string.
Example: SQL> Select length(‘University’) from dual;
Output:10
vi) Concat(str1,str2,...)-
Returns the string that result from concatenating the arguments.
Example: Select Concat(‘employee’, ‘name’) from dual;
Output: employee name
vii) Lpad(str, len, padstr)-
Returns the string str, left-padded with the string padstr to a
length of len characters.
Example: Select lpad(ename,10.’*’) from emp where
empno=7782;
viii) Rpad(str,len,padstr)-
Returns the string str, right-padded with the string padstr to a
length of len characters.
Example: Select rpad(ename,10.’*’) from emp where
empno=7782
viii) Substr(Char,m,n)-
It returns a portion of char, beginning at a character m, n
character long.
Example: Select substr(‘College’,3,4) from dual;
Output: lleg
4 Explain joins in SQL with examples. W-18, 4
S-24

28
RSCOEP COMPUTER ENGINEERING DEPARTMENT MRS.S.S.GHULE
JOIN:
A SQL join is an instruction to combine data from two sets of
data (i.e. two tables). A
JOIN clause is used to combine rows from two or more tables,
based on a related column
between them. SQL Join types are as follows:
1) INNER JOIN or EQUI JOIN:
A join which is based on equalities is called equi join. In equi
join comparison
operator “=” is used to perform a Join.
Syntax:
SELECT
tablename.column1_name,tablename.column1_name
FROM table_name1,table_name2
where
table_name1.column_name=table_name2.column_name;
Example:
Select stud_info.stud_name, stud_info.branch_code,
branch_details.location
From stud_info, branch_details
Where Stud_info.branch_code=branch_details.branch_code;
2) SELF JOIN:
The SQL SELF JOIN is used to join a table to itself, as if the
table were two
tables, temporarily renaming at least one table in the SQL
statement.
Syntax:
SELECT a.column_name, b.column_name
FROM table1 a, table1 b
WHERE a.common_filed = b.common_field;
Example:
Select x.stud_name, y.stud_name
from stud_info x, stud_info y
Where x.leader= y.stud_id;

29
RSCOEP COMPUTER ENGINEERING DEPARTMENT MRS.S.S.GHULE
3) LEFT OUTER JOIN:
A left outer join retains all of the rows of the “left” table,
regardless of whether there is a
row that matches on the “right” table.
Syntax:
Select column1name,column2name
from table1name any_alias1 ,table2name any_alias2
on any_alias1.columnname(+) = any_alias2.columnname;
OR
Select column1name,column2name
from table1name left outer join table2name
on table1name.columnname= table2name.columnname;
Example:
select last_name, department_name
from employees e, departments d
on e.department_id(+) = d.department_id;
OR
select last_name, department_name
from employees left outer join departments
on employees.department_id = departments.department_id;

4) RIGHT OUTER JOIN:


A right outer join retains all of the rows of the “right” table,
regardless of
whether there is a row that matches on the “left” table.
Syntax:
Select column1name, column2name
from table1name any_alias1, table2name any_alias2
on any_alias1.columnname =any_alias2.columnname (+);
OR
Select column1name, column2name
from table1name any_alias1 right outer join table2 name
any_alias2
on any_alias1.columnname =any_alias2.columnname;
Example:
Select last_name,department_name from employees e,
departments d on
e.department_id = d.department_id(+);
OR
Select last_name, department_name
from employees e right outer join departments d
on e.department_id = d.department_id;
5) NON EQUI JOIN:
Non equi joins is used to return result from two or more tables
where exact join is
not possible.
Syntax:
Select aliasname.column1name, aliasname.column2name
from tablename alias
where <condition using range>;

30
RSCOEP COMPUTER ENGINEERING DEPARTMENT MRS.S.S.GHULE
For example:
In emp table and salgrade table. The salgrade table contains
grade and their low
salary and high salary. Suppose you want to find the grade of
employees based on
their salaries then you can use NON EQUI join.
Select e.empno, e.ename, e.sal, s.grade
from emp e, salgrade s
where e.sal between s.lowsal and s.hisal;
4 Explain set operators with example W-18 4
Set operators combine the results of two component queries
into a single result. Queries
containing set operators are called as compound queries. Set
operators in SQL are
represented with following special keywords as: Union, Union
all, intersection & minus.
Consider data from two tables emp and employee as

1) Union: The Union of two or more sets contains all elements,


which are present in
either or both. Union works as or.
E.g. select ename from emp union select ename from
employee;
The output considering above data is :
Output.

5 Describe commit & rollback with syntax example W-18 4


Commit: Description
and syntax –
31
RSCOEP COMPUTER ENGINEERING DEPARTMENT MRS.S.S.GHULE
The COMMIT command saves all transactions to the database 1 Mark
since the last COMMIT example 1
or ROLLBACK command Mark for
The syntax: SQL> COMMIT; each
Or
COMMIT WORK;
Example :
SQL>Commit;
Rollback:
The ROLLBACK command is used to undo transactions that
have not already been
saved to the database.
The ROLLBACK command can only be used to undo
transactions since the last
COMMIT or ROLLBACK command was issued.
The syntax for ROLLBACK is:
ROLLBACK TO SAVEPOINT_NAME;
OR
ROLLBACK;
OR
ROLLBACK WORK;
Example:
SQL>ROLLBACK;
6 Consider the following schema Depositor (ACC_no, Name, W-18 6
PAN, Balance) Create a view on Depositor having attributes
(ACC_no, PAN) where balance is greater than 100000.
create view v1 Correct logic
as 3M, Correct
select ACC_No,PAN syntax :3M
from Depositor
where balance > 100000;
7 Consider the following database Employee(emp_id, W-18 6
emp_name, emp_city, emp_addr, emp_dept, join_date) i)
Display the emp_id, of employee who live in city ‘Pune’ or
‘Nagpur’. ii) Change employee name, ‘Aayush’ to ‘Aayan’. iii)
Display the total number of employee whose dept is 50.
i) Display the emp_id of employee who live in city ‘Pune’ or Each query :
‘Nagpur’ 2M
select emp_id from Employee
where emp_city=’Pune’ or emp_city=’Nagpur’
ii) Change the employee name ‘Ayush’ to ‘Ayan’
update Employee set emp_name=’Ayan’
where emp_name=’Ayush’
iii) Display the total number of employee whose dept is 50
Select count(*)from Employee where emp_dept=50;

8 Create a sequence i) Sequence name is Seq _ 1, Start with 1, W-18 6


increment by 1, minimum value 1, maximum value 20. ii) Use
a seq_1 to insert the values into table Student (ID Number (10),

32
RSCOEP COMPUTER ENGINEERING DEPARTMENT MRS.S.S.GHULE
Name char (20)); iii) Change the seq_ 1 max value 20 to 50. iv)
Drop the sequence.
i) create sequence Seq_1 start with 1 increment by 1 minvalue Query 1: 2M,
1 maxvalue Query 2: 2M,
20; Query 3 : 1M,
ii) insert into student values(Seq_1.nextval,’ABC’) Query 4 : 1M
iii) Alter sequence Seq_1 maxvalue 50;
iv) Drop sequence Seq_1

9 I)Create user ‘rahul’ W-18 6


ii) grant create ,select,insert,update,delete,drop priveileges to
‘rahul’
iii) removes the select privilege from user”Rahul”
(i) create user Rahul identified by rahul1234;
(ii)
1) assuming table Employee for granting permissions to user
‘Rahul’ for select,
insert, update and delete privilege)
Grant select, insert,update,delete on employee to Rahul;
2) for create and drop privilege which are system privileges not
specific to any
object such as table
Grant connect, resource, DBA to Rahul;
iii) (assuming table Employee for revoking permissions to user
‘Rahul’)
Revoke select on Employee from Rahul

1 List DCL commands. S-19 2


1. GRANT
2. REVOKE
2 Explain difference between delete and truncate command with S-19 4
example.

33
RSCOEP COMPUTER ENGINEERING DEPARTMENT MRS.S.S.GHULE
3 List the SQL ope S-19 4
rations and explain range searching operation ‘between’ and
pattern matching operator ‘like’ with example.
Types of SQL operators :
1) SQL Arithmetic Operators
2) SQL Comparison Operators
3) SQL Logical Operators
Arithmetic operators are used to perform arithmetic operations List of
on operators :
numbers. They are +,-,*, / and %. 2M,
Comparison operators are used in between two variables to between
compare operator :
their values. They are <,>,<=,>=,=,!=or <>,!< and !>.' 1M,
Logical operators are used for the Boolean results in sql queries Like
for operator :
comparison of values from the attributes of the tables. Eg: Any, 1M
Exists,
All, Like, Between, In etc.
Between operator: The BETWEEN operator is used to search
for
values that are within a set of values, given the minimum value
and the maximum value inclusive of both the limits.
Eg: select * from emp where salary between 40000 and 50000;

34
RSCOEP COMPUTER ENGINEERING DEPARTMENT MRS.S.S.GHULE
This will results in rows from emp table where salary falls in
the range of 40000 to 50000.
Like operator :
The LIKE operator is used to compare a value to similar values
using
wildcard operators. It uses two wild characters as ‘%’ and ‘_’
where ‘%’
represents all characters of the pattern and ‘_’ represents one
single character from pattern.
Eg :
Select ename from emp where ename like ‘S%’;
This will return all employee names starting with ‘S’.
Select ename from emp where ename like ‘_a%;
This will return all employee names whose second character is
‘a’
4 Write syntax for creating synonyms with example. S-19 2
Syntax to create synonym: 1 M for
CREATE SYNONYM SYNONYM_name correct
FOR Table_name; syntax, 1 M
Example to create synonym: for
CREATE SYNONYM offices correct
FOR locations example

5 Write and explain syntax for creating view with example. S-19 4
A view contains rows and columns, just like a real table. The
fields in a view are fields from one or more real tables in the
database.
View has two types:
1. Simple view: The fields in a view are fields from one table
in the
database.
2. Complex view: The fields in a view are fields from more
than one table in the database. You can add SQL functions,
WHERE, and JOIN statements to a view and present the data
as if the data were coming
from different table.
CREATE VIEW Syntax
Create view view_name As
Select column1, column2…
From table_name
Where condition ;
Example
Create view mumbai_customers AS
Select customer_name,contact_name
From customers
Where city=’Mumbai’;
6 Explain any four aggregate functions with example. S-19 4
W-23

35
RSCOEP COMPUTER ENGINEERING DEPARTMENT MRS.S.S.GHULE
An aggregate function is a function where the values of
multiple rows are grouped together as input on certain criteria
to form a single value of
more significant meaning.
Aggregate functions are :
1) Count()
2) Sum()
3) Avg()
4) Min()
5) Max()
1. Count () - 1) It returns number of rows from the given table
if no attribute is mentioned.
2) If some attribute is mentioned, it gives total number of not
null valfor that attribute.
Eg :Select count(*) from emp;
Returns total number of records from emp table.
1) Select count(telephone) from emp;
Returns total number of employees having telephone numbers.
2. Sum() - It give total of all values from a numeric attribute of
the given table,
Eg :Select sum(salary) from emp;
Returns total salary drawn of all employees from the emp table.
3. Avg () - It gives average of all the numeric values of the
given attribute from the table.
Eg :Select Avg(salary) from emp;
Returns average salary of employees from emp table.
4. Min () - It gives minimum of all the values of the numeric
given attribute from the table.
Eg :Select Min(salary) from emp;
Returns minimum salary value from emp table,
5. Max () - It gives maximum of all the values of the numeric
given attribute from the table.
Eg :Select Max(salary) from emp;
retunes maximum salary value from emp tableues

7 Create simple and composite index. Write command to drop S-19 6


above index.
Create simple index Simple index
Syntax: Create index index_name on <tablename><column 2M,
name>; Composite
(OR) index: 2M
E.g.: Create index idx_empno on employee (empno); Drop index
Create composite index: 2M
Syntax: Create index index_name on (Note: Either
<tablename><Column_name1, syntax or
Column_name2>; example can
(OR) be
E.g.: Create index idx_ename_eno on employee (ename, considered.
empno); Any other
Drop Index: example

36
RSCOEP COMPUTER ENGINEERING DEPARTMENT MRS.S.S.GHULE
Syntax: Drop index <index_name>; allowed.)
(OR)
E.g. (Assuming idx_empno created on employee table)
Drop index idx_empno;
8 Consider the table Student (name, marks, dept, age, place, S-19 6
phone, birthdate) Write SQL query for following : (i) To list
students having place as ‘Pune’ or ‘Jalgaon’. (ii) To list
students having same department (dept) as that of ‘Rachana’.
(iii) To change marks of ‘Rahul’ from 81 to 96. (iv) To list
student name and marks from ‘Computer’ dept. (v) To list
student name who have marks less than 40. (vi) To list students
who are not from ‘Mumbai’.
select name from Student where place= ‘Pune’ or Each Correct
place=’Jalgaon’; Query : 1M
(OR)
select name from Students where place in(‘Pune’,‘Jalgaon’);
ii) select name from Student where dept=(select dept from
student where
name=’Rachana’);
iii) update Student set marks=96 where name= ‘Rahul’;
v)select name,marks from Student where dept=‘Computer’;
iv) select name from Student where marks<40;
v) select * from Student where place != ‘Mumbai’;
9 i) Write a command to create table student (RNo., name, S-19 6
marks, dept.) with proper datatype and RNo as primary key.
(ii) Write a command to create and drop sequence.
i) create table student
(
RNO number(5) constraint student _RNOpk primary key,
name varchar2(20),
marks number(4),
dept varchar2(20)
);
(OR)
create table student
(
RNO number(5) ,
name varchar2(20),
marks number(4),
dept varchar2(20),
constraint student_RNO_pk primary key(RNO),
);
ii) Create Sequence:
Create sequence <seq_name>
Start with [initial value]
Increment by [value]
Minvalue [minimum value]
Maxvalue [maximum value]
[cycle/no cycle]
[{cache value / No cache}]

37
RSCOEP COMPUTER ENGINEERING DEPARTMENT MRS.S.S.GHULE
[{order / No order}];
(OR)
(Creating sequence for Employee number of emp table.)
Create sequence emp_eno_seq
start with 1
increment by 1
maxvalue 100
no cycle
no cache;
Drop sequence:
Drop sequence<Sequence Name>;
(OR)
Drop sequence emp_eno_seq

10 Write SQL command for following : (i) Create user (ii) Grant S-19 6
privileges to user (iii) Remove privileges from user
i) Create user Each correct
CREATE USER <username> IDENTIFIED BY <password>; command:
(OR) 2M
CREATE USER RAJ IDENTIFIED BY RAJ123; (Note: Either
ii) Grant privileges to user. syntax or
GRANT <privilege list> ON <relation name or view name> example can
TO<user list>; be
(OR) considered.
(assuming table Employee for granting permissions to user Any other
‘RAJ’ example
for select, insert, update and delete privilege) allowed
GRANT SELECT, INSERT,UPDATE,DELETE ON
EMPLOYEE TO RAJ;
Iii) Remove privileges from user.
REVOKE <privilege list> ON <relation name or view name >
FROM <user list>;
(OR)
(assuming table Employee for revoking permissions to user
‘RAJ)
REVOKE SELECT, INSERT,UPDATE,DELETE ON
EMPLOYEE FROM RAJ;

1 List any four string functions in SQL. W-19 2


Initcap(String) – converts first character of string to upper case four
Upper(String) – converts the string to upper case string
Lower(String) – converts string to lower case function
Length(String) – returns the number of characters in the string s ½M
Instr(String, sub) – returns the location of the substring each
Lpad(String,char,number) – returns the string left padded with
the
character specified to a total of length specified.
Rpad(String,char,number) – returns the string right padded
with the

38
RSCOEP COMPUTER ENGINEERING DEPARTMENT MRS.S.S.GHULE
character specified to a total of length specified. Ltrim(String)
-removes white space or other specified characters from the left
end of the string Rtrim(String)--removes white space or other
specified characters from the right end of the string
Replace(String, char,char) – replace all occurrence of a
substring by another substring Substring(String,number) –
extracts substring from the string Translate(String,char,char) –
replace all occurrence of characters by other characters
2 Enlist DML commands. W-19 2
- used to insert new row into table Any 2
- used to delete a row from the table comman ds
– used to modify data in the table. 1M each
Select – used to view data from a table.
3 Explain any four set operators in SQL with example. W-19 4
Set operators combine the results of two component queries 1M each
into a for
single result. Queries containing set operators are called as explanat
compound queries. Set operators in SQL are represented with ion of
following special operator
keywords as: Union, Union all, intersection & minus. s with
1) Union: The Union of two or more sets contains all elements, example
which are present in either or both. Union works as or. The
duplicates of both the tables will appear only once.
E.g. select ename from emp1 union select ename from emp2;
2) Union all: The Union of 2 or more sets contains all elements,
which are present in both, including duplicates.
E.g. select ename from emp1 union all select ename from
emp2;
3) Intersection: The intersection of two sets includes elements
which are present in both.
E.g. select ename from emp1 intersect select ename from
emp2;
4) Minus: The minus of two sets includes elements from set1
minus
elements of set2.
E.g. select ename from emp1 minus select ename from emp2;

4 Describe create & alter command with syntax & example. W-19 4
1) The SQL CREATE TABLE statement is used to create a Each
new comman
table. d 2M
Syntax
The basic syntax of the CREATE TABLE statement is as
follows –
CREATE TABLE table_name
(
column1 datatype (size),
column2 datatype(size),
column3 datatype(size),
....
39
RSCOEP COMPUTER ENGINEERING DEPARTMENT MRS.S.S.GHULE
);
Example:
CREATE TABLE Persons
(
PersonIDnumber(10),
LastNamevarchar2(20),
FirstNamevarchar2(20),
Address varchar2(20),
City varchar2(20)
);
2)The ALTER TABLE statement is used to add, delete, or
modify columns in an existing table.
The ALTER TABLE statement is also used to add and drop
various constraints on an existing table.
i) To add Columns in a table
Syntax:ALTER TABLE table_name
ADD column_name datatype;
Example
ALTER TABLE Customers
ADD Email varchar2(20);
ii) To delete a column in a table
ALTER TABLE table_name
DROP COLUMN column_name;
Example
ALTER TABLE Customers
DROP COLUMN Email;
iii) To modify a column in a table
Syntax:
ALTER TABLE table_name
MODIFY COLUMN column_name datatype;
Example
ALTER TABLE Customers
MODIFY COLUMN customeridnumeric(10);
iv) To add Constraints in A table
Syntax:
ALTER TABLE table_name
ADD constraint constraintname (column_name);
Example:
ALTER TABLE Customers
ADD constraint primary key(CustomerID);
5 Describe Views and write a command to create view. W-19 4
A view is a virtual table based on the result set of the SQL Explana
statement. tion 3M
The fields in a view are fields from one or more than one table General
in the database. SQL functions, where, join statements can be syntax/
added to a view and the data in it can be presented as if it were example
from one table. The database engine recreates the data, using 1M
the view’s SQL statement, every time a user queries a view. A
view can be updated using the create or replace view command.
For deleting a view, drop query can be used.

40
RSCOEP COMPUTER ENGINEERING DEPARTMENT MRS.S.S.GHULE
General syntax to create a view:
create view viewname as select query.
Eg:
create view vw_student as select stud_id, stud_name,ssc_per
from
student;
6 Define index. Explain it’s types. W-19 4
An Index is a schema object. It is used by the oracle server to Definitio
improve the speed of retrieval of the rows from a table .Indexes n 1M
are of two types based on number of columns included in the Each
index. type
The types of index are: 1½M
1) Simple index: An index created on a single column of table
is
called as simple index
Syntax:
SQL>Create Index index_name on tablename(attribute);
Example:Create index emp_index on emp(empno);
2) Composite Index: An index created on more than one
column is called composite index.
Syntax:
SQL>Create Index index_name on
tablename(attribute1,attribute2);
Example: Create index emp_index on emp(empno,ename);

7 Write a command to create table student (rollno, Stud_name, W-19 6


branch, class, DOB, City, Contact_no) and write down queries
for following : (i) Insert one row into the table (ii) Save the data
(iii) Insert second row into the table (iv) Undo the insertion of
second row (v) Create save point S1 . (vi) Insert one row into
the table.
SQL>Create table student( Each
Rollno number(5), correct
Stud_name char(10, Query
branch varchar(10), ½M
class varchar(10), each
DOB date,
city varchar(15),
Contact_no number(12)
);
(i) Insert one row into the table:
SQL>Insert into student
values(1,‟Ram‟,‟CO‟,‟FirstYear‟,‟12-
jun-2001‟,‟Pune‟,98576867)
(ii) Save the data:
SQL> commit;
( OR )
SQL> commit work;
(iii) Insert second row into the table:

41
RSCOEP COMPUTER ENGINEERING DEPARTMENT MRS.S.S.GHULE
SQL>Insert into student
values(2,‟Raj‟,‟CO‟,‟FirstYear‟,‟22-
Sep2002‟,‟Mumbai‟,98896863)
(iv)Undo the insertion of second row:
SQL> rollback;
( OR)
SQL> rollback work;
(v)Create savepoint s1:
SQL>Savepoint s1;
(vi) insert one row into the table:
SQL>Insert into student
values(3,‟Beena‟,‟CO‟,‟FirstYear‟,‟30-
Dec-2002‟,‟Mumbai‟,97846455)

8 Consider following schema : EMP (empno, deptno, ename, W-19 6


salary, designation, join_date, DOB, dept_location). Write
down SQL queries for following : (i) Display employees name
& number in decreasing order of salary. (ii) Display employee
name & employee number whose designation is Manager. (iii)
Display age of employees with ename. (iv) Display total salary
of all employees. (v) Display employee names having deptno
as 20 and dept_location is Mumbai. (vi) Display name of
employee who earned lowest salary.
(i) Display employees name &number in descending order of
salary:
SQL> select ename,empno from EMP order by salary desc;
(ii) Display employee name & employee number whose
designation
is Manager.
SQL> select ename,empno from EMP where
designation=‟Manager‟;
(iii) Display age of employees with ename
SQL>select round ( (sysdate - DOB ) /365, 0 ) as “age”,ename
from EMP;
OR
select months_between(TRUNC(sysdate),DOB)/12 as “age”
,ename from EMP ;
(**Note consider any other logic also)
(iv)Display total salary of all employees.
SQL> select sum(salary) from EMP;
(v) Display employee names having deptno as 20 and
dept_location is
Mumbai.
SQL> select enamefrom EMP where deptno=20 and
dept_location=‟Mumbai‟;
(vi) Display name of employee who earned lowest salary
SQL> select ename from EMP where salary=(select
min(salary)
from EMP);

42
RSCOEP COMPUTER ENGINEERING DEPARTMENT MRS.S.S.GHULE
9 Consider the structure for book table as Book-Master (bookid, W-19 6
bookname, author, no_of copies, price) Write down SQL
queries for following (i) Write a command to create
Book_master table. (ii) Get authorwise list of all books. (iii)
Display all books whose price is between ` 500 & ` 800. (iv)
Display all books with details whose name start with ‘D’. (v)
Display all books whose price is above ` 700. (vi) Display all
books whose number of copies are less than 10.
(i) Write a command to create Book_Master table table. Each
SQL>Create table Book-Master( correct
bookid number(5), Query
bookname char(10), 1M
authorvarchar(20),
no_of_copiesnumber(10),
price number(10,2)
);
(ii) Get authorwise list of all books.
SQL>Select sum(no_of copies) from Book_Master group by
author;
(iii) Display all books whose price is between Rs.500 & Rs. 800
SQL> Select * from Book_Master where price between 500
and
800;
OR
SQL> Select * from Book_Master where price >=500 and
price<=800;
(iv) Display all books with details whose name start with ‘D’
SQL> Select bookname from Book_Master where bookname
like
„D%‟;
(v) Display all books whose price is above Rs. 700
SQL>Select * from Book_Master where price >700;
(vi) Display all books whose number of copies are less than 10
SQL>Select * from Book_Master where no_of_copies<10;

1 State the use of Avg function with example S-22 2


The AVG() function returns the average value of a numeric
column
Ex: Find the average price of all products:

SELECT AVG(Price)
FROM Products;
2 List any four data types in sql S-22 2
Numeric data types such as: INT , TINYINT , BIGINT ,
FLOAT , REAL , etc.
Date and Time data types such as: DATE , TIME , DATETIME
, etc.
Character and String data types such as: CHAR , VARCHAR
, TEXT , etc.

43
RSCOEP COMPUTER ENGINEERING DEPARTMENT MRS.S.S.GHULE
Unicode character string data types such as: NCHAR ,
NVARCHAR , NTEXT , etc
3 Explain any two DDL commands along with example. S-22 4

Data Definition Language(DDL) is a subset of SQL and a part


of DBMS(Database Management System). DDL consist of
Commands to commands like CREATE, ALTER,
TRUNCATE and DROP. These commands are used to create
or modify the tables in SQL.
DDL Commands :
In this section, We will cover the following DDL commands as
follows.
Create
Alter
truncate
drop
Rename
Let’s discuss it one by one.
Command-1 :
CREATE :
This command is used to create a new table in SQL. The user
has to give information like table name, column names, and
their datatypes.
Syntax –
CREATE TABLE table_name
(
column_1 datatype,
column_2 datatype,
column_3 datatype,
....
);
Example –
We need to create a table for storing Student information of a
particular College. Create syntax would be as below.
CREATE TABLE Student_info
(
College_Id number(2),
College_name varchar(30),
Branch varchar(10)
);
Command-2 :
ALTER :
This command is used to add, delete or change columns in the
existing table. The user needs to know the existing table name
and can do add, delete or modify tasks easily.

Syntax –
Syntax to add a column to an existing table.

ALTER TABLE table_name

44
RSCOEP COMPUTER ENGINEERING DEPARTMENT MRS.S.S.GHULE
ADD column_name datatype;
Example –
In our Student_info table, we want to add a new column for
CGPA. The syntax would be as below as follows.

ALTER TABLE Student_info


ADD CGPA number;
Command-3 :
TRUNCATE :
This command is used to remove all rows from the table, but
the structure of the table still exists.

Syntax –
Syntax to remove an existing table.

TRUNCATE TABLE table_name;


Example –
The College Authority wants to remove the details of all
students for new batches but wants to keep the table structure.
The command they can use is as follows.

TRUNCATE TABLE Student_info;


Command-4 :
DROP :
This command is used to remove an existing table along with
its structure from the Database.

Syntax –
Syntax to drop an existing table.

DROP TABLE table_name;


Example –
If the College Authority wants to change their Database by
deleting the Student_info Table.
DROP TABLE Student_info;
Command -5
RENAME:
It is possible to change name of table with or without data in it
using simple RENAME command.
We can rename any table object at any point of time.

Syntax –
RENAME TABLE <Table Name> To <New_Table_Name>;
Example:
If you want to change the name of the table from Employee to
Emp we can use rename command as
RENAME TABLE Employee To EMP; syntax for i) Create
Index ii) Drop Index
4 Describe the concept of view with example. State its purpose. S-22 4

45
RSCOEP COMPUTER ENGINEERING DEPARTMENT MRS.S.S.GHULE
A view is a virtual table based on the result set of the SQL
statement.
The fields in a view are fields from one or more than one table
in the
database. SQL functions, where, join statements can be added
to a
view and the data in it can be presented as if it were from one
table.
The database engine recreates the data, using the view’s SQL
statement, every time a user queries a view. A view can be
updated
using the create or replace view command. For deleting a view,
drop
query can be used.
General syntax to create a view:
create view viewname as select query.
Eg:
create view vw_student as select stud_id, stud_name,ssc_per
from
student;
5 i) Create user ‘RAM’. ii) Grant create, select, insert, update, S-22 6
delete privileges to user ‘RAM’. iii) Remove update privilege
from user ‘RAM’
I)CREATE USER RAM IDENTIFIED BY RAM123;
ii) CREATE USER RAJ IDENTIFIED BY RAJ123;
ii) Grant privileges to user.
GRANT <privilege list> ON <relation name or view name>
TO<user list>;
(OR)
(assuming table Employee for granting permissions to user
‘RAM’
for select, insert, update and delete privilege)
GRANT SELECT, INSERT,UPDATE,DELETE ON
EMPLOYEE TO RAM;
Iii) Remove privileges from user.
REVOKE <privilege list> ON <relation name or view name >
FROM <user list>;
(OR)
(assuming table Employee for revoking permissions to user
‘RAM)
REVOKE SELECT, INSERT,UPDATE,DELETE ON
EMPLOYEE FROM RAM;

6 Consider the schema Customer (Cust-id, Cust_name, S-22 6


Cust_addr, Cust_city) i) Create a view on Customer (Cust_id,
Cust_name) where Cust_city is ‘Pune’ ii) Create a sequence on
Cust_id
CREATE VIEW Syntax:
create view view_name As
select column1, column2…
46
RSCOEP COMPUTER ENGINEERING DEPARTMENT MRS.S.S.GHULE
from table_name
where condition ;
DROP VIEW Syntax:
DROP VIEW view_name;
7 i) Create table Student (S_id, S_name, S_addr, S_marks) with S-22 6
proper data type and size. ii) Insert row (5, ‘ABC’, ‘RRRRR’,
79) into student table. iii) Update marks of student 85 where
S_id is 5.

8 Consider the following table employee (Emp_id, Emp_name, S-22 6


Emp_age) i) Display details of employees whose age is less
than 30. ii) Display details of employees whose age is in
between the range 30 to 60. iii) Display total number of
employee whose age is 60. iv) Display names of employees
whose name starts with 'S'. v) Display details of employees
whose name end with 'd'. vi) Display details of employees
whose age is greater than 50 and whose name contain 'e'.

1 Write syntax for creating and dropping views. W-22 2


CREATE VIEW Syntax:
create view view_name As
select column1, column2…
from table_name
where condition ;
DROP VIEW Syntax:
DROP VIEW view_name;
2 Write syntax for creating and Renaming a table. W-22 2
Syntax of the CREATE TABLE statement is as follows: Correct
CREATE TABLE table_name Syntax
( of Create
column1 datatype (size), Table:
column2 datatype(size), 1M,
column3 datatype(size), Correct
.... Syntax
); of Rename
Syntax of RENAME TABLE statement is as follows: Table: 1M
RENAME old_table _name To new_table_name ;

3 Enlist arithmetic and logical SQL operators. W-22 2


SQL Arithmetic Operators: Addition Operator (+) SQL
Subtraction Operator (-) arithmetic
Multiplication Operator (+) operators:
Division Operator (-) 1M, SQL
Modulus Operator (+) logical
SQL Logical Operators: operators:
ALL operator 1M
AND operator
OR operator
BETWEEN operator
47
RSCOEP COMPUTER ENGINEERING DEPARTMENT MRS.S.S.GHULE
IN operator
NOT operator
ANY operator
LIKE operator
4 Write SQL queries for following: i) Create table student with W-22 4
following attributes using suitable data types. Roll no., as
primary key, name, marks as not null and city. ii) Add column
Date of Birth in above student table. iii) Increase the size of
attribute name by 10 in above student table. iv) Change name
of Student table to stud.
(
CREATE TABLE Student
( Rollno int PRIMARY KEY,
name varchar(30) NOT NULL,
marks int NOT NULL,
city varchar(20)
);
ii)
ALTER TABLE student
ADD DateofBirth varchar(20);
iii)
ALTER TABLE student
Modify name varchar(40);
iv)
RENAME Student to Stud;

5 State the use of group by and order by clauses. W-22 4


Group by Clause: 2 M=group
Group by clause is used to collect the data as multiple records by
and group them to 2 M=order by
produce the result.
Syntax:
1. SELECT column_name, function(column_name)
2. FROM table_name
3. WHERE condition
4. GROUP BY column_name;
Ex: select avg(sal) from emp_details group by deptno;
Order by Clause:
To view the data in sorted order, the order by clause is used.
By default, the data is sorted in ascending order.
Syntax:
5. SELECT expressions
6. FROM tables
7. [WHERE conditions]
8. ORDER BY expression [ ASC | DESC ];
Ex: select deptno from emp_details order by deptno;
Ex: select deptno from emp_details order by deptno desc; (for
descending order)
6 Write and Explain the syntax for creating, Altering and W-22 6
dropping the sequence.
48
RSCOEP COMPUTER ENGINEERING DEPARTMENT MRS.S.S.GHULE
Syntax for creating sequence: 2M
CREATE SEQUENCE sequence_name
START WITH initial_value
INCREMENT BY increment_value
MINVALUE minimum value
MAXVALUE maximum value
CYCLE|NOCYCLE ;
.where as:sequence_name: Name of the sequence.
initial_value: starting value from where the sequence starts.
Initial_value should be greater than or equal to minimum value
and less than equal to maximum value.increment_value: Value
by which sequence will increment itself. Increment_value can
be positive or negative.minimum_value: Minimum value of the 2M
sequence.maximum_value: Maximum value of the sequence.
cycle: When sequence reaches its set_limit
it starts from beginning.nocycle: An exception will be thrown
if sequence exceeds its max_value.
Example:
CREATE SEQUENCE sequence_1
start with 1
increment by 1
minvalue 0
maxvalue 100
cycle;
Alter sequence:
Syntax:
alter sequence <sequence_name> maxvalue <number>;
Alter sequence can change the maxvalue in the sequence 2M
created.
Dropping sequence:
Syntax:
drop sequence <sequence_name>;
To drop the sequence the DROP command is used.
7 Write and Explain the syntax for creating and dropping indexes W-22 4
with an example.
CREATE INDEX Correct
The CREATE INDEX command is used to create indexes in explanation
tables. It allows duplicate values. Indexes are used to retrieve Of
data from the database very fast. The DROP
users cannot see the indexes; they are just used to speed up INDEX
searches/queries. Syntax with
Syntax: example: 2M
CREATE INDEX index_name
ON table_name (column1, column2, ...);
Example:
The following SQL creates an index named id_firstname on the
FirstName column in
the Student table:
CREATE INDEX id_firstname
ON Student (FirstName);

49
RSCOEP COMPUTER ENGINEERING DEPARTMENT MRS.S.S.GHULE
DROP INDEX
The DROP INDEX statement is used to delete an index in a
table.
Syntax:
DROP INDEX index_name ON table_name;
Example:
DROP INDEX id_firstname ON Student;
8 State the use of group by and order by clauses. W-22 4
Group by Clause: 2 M=
Group by clause is used to collect the data as multiple records group by
and group them to produce the result. 2 M=
Syntax: order by
1. SELECT column_name, function(column_name)
2. FROM table_name
3. WHERE condition
4. GROUP BY column_name;
Ex: select avg(sal) from emp_details group by deptno;
Order by Clause:
To view the data in sorted order, the order by clause is used.
By default, the data is sorted in ascending order.
Syntax:
5. SELECT expressions
6. FROM tables
7. [WHERE conditions]
8. ORDER BY expression [ ASC | DESC ];
Ex: select deptno from emp_details order by deptno;
Ex: select deptno from emp_details order by deptno desc; (for
descending order
9 Write the SQL queries for following EMP table. Emp (empno, W-22 6
deptno, ename, salary, designation, city.) i) Display average
salary of all employees. ii) Display names of employees who
stay in Mumbai or Pune. iii) Set the salary of employee
'Ramesh' to 50000. iv)Display names of employees whose
salaries are less than 50000. v) Remove the Record of
employees whose deptno is 10. vi) Remove the column deptno
from EMP table.
i. select avg(salary) from emp; 1 M each
ii. select ename from emp where city=’Mumbai’ or
city=’Pune’;
iii. update emp set salary=50000 where ename=’Ramesh’;
iv. select ename from emp where salary<50000;
v. delete from emp where deptno=10;
vi. alter table emp drop column deptno;
10 Write SQL queries for following. Consider table stud (roll no, W-22 6
name, subl, sub2, sub3) i) Display names of student who got
minimum mark in subl. ii) Display names of students who got
above 40 marks in sub2. iii) Display count of Students failed in
sub2. iv) Display average marks of subl of all students. v)
Display names of students whose name start with 'A' by

50
RSCOEP COMPUTER ENGINEERING DEPARTMENT MRS.S.S.GHULE
arranging them in ascending order of subl marks. vi) Display
student name whose name ends with h' and subject 2 marks ar6
i. select name from stud where sub1= (select min(sub1) from 1 M each
stud);
ii. select name from stud where sub2>40;
iii. select count(*) from stud where sub2<40;
iv. select avg(sub1) from stud;
v. select name from stud where name like 'A%' order by sub1;
vi. select name from stud where name like '%h' and sub2
between 60 and 75;
11 Write SQL queries for following. 1) Create user named 'user1' W-22 6
having Password '1234 ii) Assign 'insert' and update' Privilege
to 'userl". ii) Remove update Privilege assigned to the userl. iv)
Assign the resource Pemission to userl.
i. create user user1 identified by 1234; 1½M
ii. grant insert, update on system.emp to user1; each
iii. revoke update on system.emp from user1;
iv. grant create session, unlimited tablespace, create table to
user1;

1 List any two DDL Commands With syntax S-23 2


DDL commands Any two DDL
1.Create command s
Syntax : with syntax
create table (Column_name1 datatype1(size1), column_name2 1M each
Datatype 2(size2),
Column_nameN DatatypeN(size n));
2. Drop
Syntax:
drop table < table_name>;
3. Desc
Syntax: describe < table_name> ;
OR
Desc < table_name> ;
4. Truncate
Syntax: truncate table < table_name> ;
5. Alter
Syntax: i) Alter table < table_name> add (Column_name
Datatype (size));
ii) Alter table <table_name> drop(Column_name);
iii) Alter table <table_name> rename column(old
column_name to new
column_name);

2 Describe grant and Revoke commands with example S-23 4


Grant: This command is used to give permission to user to do Each
operations on the command
other user‟s object. with
example
51
RSCOEP COMPUTER ENGINEERING DEPARTMENT MRS.S.S.GHULE
Syntax: Grant <object privileges> on <object name> to 2M
<User/Public/Role>[with
grant option];
Example: Grant select, update on emp to user1;
Revoke: This command is used to withdraw the privilege that
has been granted to
a user.
Syntax: Revoke <object privileges> on <object name> from
<<User/Public/Role>;
Example: Revoke select, update on emp from user1;

3 Explain savcpoint and rollback command with example S-23 4


Savepoint : This command is used to temporarily save a Explanati
transaction so that you on of
can rollback to that point whenever required. savepoint
Syntax : with
Savepointsavepoint_name; example
Eg :savepoint s1; 2M
Rollback : Explanati
This command restores the database to last committed state. It on of
is also used with rollback
SAVEPOINT command to jump to a savepoint in an ongoing with
transaction. example
If we have used the UPDATE command to make some changes 2M
into the database,
and realise that those changes were not required, then we can
use the
ROLLBACK command to rollback those changes, if they were
not committed
using the COMMIT command.
Syntax :
Rollback [tosavepoint_name];
Eg Rollback to s1;
Example :
INSERT INTO class VALUES(5, 'Rahul');
COMMIT;
UPDATE class SET name = 'Abhijit' WHERE id = '5';
SAVEPOINT s1;
INSERT INTO class VALUES(6, 'Chris');
Rollback to s1;
This will undone the transaction of last insert, i.e. till savepoint
s1;

4 Explain any DML Commands with syntax and example S-23 4

DML commands:
- used to insert new row into table
- used to delete a row from the table
– used to modify data in the table.
– used to view data from a table.

52
RSCOEP COMPUTER ENGINEERING DEPARTMENT MRS.S.S.GHULE
1) Insert : For adding records in table:
We use Insert into command for adding/inserting data into
table.
Syntax:
Insert into <table name> values (value1, value2, value3…);
Ex:
insert into Student values(1,‟xyz‟,‟12-Jan-1990‟,88,10);
OR
Ex:Insert into
Studentvalues(&R_No,‟&Name‟,‟&DOB‟,&Percentage,&D
_No);
2) Update : For modifying records in table
We use update command for modifying data of a table.
Syntax:
Update <table name>set columnname1=expression where
<condition>;
Ex:
update Student set DOB=‟22-feb-1995‟ where R_No=3;
3) Delete : For deleting records from table:
We use delete command for deleting data of a table.
Syntax:
Delete from <table name>[where <condition>];
Ex:
delete from Student where R_No=2;
4) Select : For viewing the records from table
We use select command for displaying or viewing the records
from a table or
tables.
Syntax:
Select <*/ list of columns> from <table name> [where
<condition> ] ;
Ex :
Select * from Student;
Select R_N0,Name,DOB from Student where Percentage > 80;
5 Explain any two types of join with example. S-23 6
JOIN: Explanati
A SQL join is an instruction to combine data from two sets of on of any
data (i.e. two two types
tables). A with
JOIN clause is used to combine rows from two or more tables, example
based on a 3M each
related column between them. SQL Join types are as follows:
1) EQUI JOIN:
A join which is based on equalities is called equi join. In equi
join comparison
operator “=” is used to perform a Join.
Syntax:
SELECT
tablename.column1_name,tablename.column2_name

53
RSCOEP COMPUTER ENGINEERING DEPARTMENT MRS.S.S.GHULE
FROM table_name1,table_name2
where
table_name1.column_name=table_name2.column_name;
Example:
Select stud_info.stud_name, stud_info.branch_code,
branch_details.location
From stud_info, branch_details
Where Stud_info.branch_code=branch_details.branch_code;
2) SELF JOIN:
The SQL SELF JOIN is used to join a table to itself, as if the
table were two
tables,temporarily renaming at least one table in the SQL
statement.
Syntax:
SELECT a.column_name, b.column_name
FROM table1 a, table1 b
WHERE a.common_filed = b.common_field;
Example:
Select x.stud_name, y.stud_name
from stud_info x, stud_info y
Where x.leader= y.stud_id;
3) INNER JOIN:The INNER JOIN command returns rows that
have
matching values in both tables.
Syntax:
Select column1_name,column2_name
from table1name INNER JOIN table2name
on table1name.columnname= table2name.columnname;
Example:
Select last_name, department_name
from employees inner join departments
on employees.department_id = departments.department_id;
4) LEFT OUTER JOIN:
A left outer join retains all of the rows of the “left” table,
regardless of whether there is a row that matches on the “right”
table.
Syntax:
Select column1_name,column2_name
from table1name any_alias1 ,table2name any_alias2
on any_alias1.columnname(+) = any_alias2.columnname;
OR
Select column1_name,column2_name from table1name left
outer join table2name
on table1name.columnname= table2name.columnname;
Example:
select last_name, department_name
from employees e, departments d
on e.department_id(+) = d.department_id;
OR
select last_name, department_name

54
RSCOEP COMPUTER ENGINEERING DEPARTMENT MRS.S.S.GHULE
from employees left outer join departments
on employees.department_id = departments.department_id;
5) RIGHT OUTER JOIN:
A right outer join retains all of the rows of the “right” table,
regardless of whether there is a row that matches on the “left”
table.
Syntax:
Select column1name, column2name from table1name
any_alias1, table2name any_alias2
on any_alias1.columnname =any_alias2.columnname (+);
OR
Select column1name, column2name from table1name
any_alias1 right outer join table2 name any_alias2
on any_alias1.columnname =any_alias2.columnname;
6 Explain view with example S-23 4
A view is a logical table based on another table.View logically Explanati
represents subsets of data from one or more tables .A view on
contains no data of it‟s own but is like a window through which 2M
data from tables can be viewed or changed .The tables on which Example
the view is based are called base tables.SQL functions, where, 2M
join statements can be added to a view and the data in it
can be presented as if it were from one table.The database
engine recreates the data, using the view‟s SQL statement,
every time a user queries a view. A view can be updated using
the create or replace view command. For deleting a view,
dropquery can be used.General syntax to create a view:
create view viewname as select query.
Example:
create view vw_student as select stud_id, stud_name,ssc_per
from
student;

1 List any four DML Commands With syntax W-23 2


1) Insert - used to insert new row into table
INSERT INTO table_name (column1, column2, ...) VALUES
(value1, value2,...);
OR
INSERT INTO table_name VALUES (value1, value2, value3,
...);
2) Delete- used to delete a row from the table
DELETE FROM table_name WHERE condition;
3) Update – used to modify data in the table.
UPDATE table_name SET column1 = value1, column2 =
value2, ...
WHERE condition;
4) Select – used to view data from a table.
SELECT column1, column2, ...FROM table_name
2 Enlist types of SQL Joins W-23 2
1) Inner Join Any 4 join
55
RSCOEP COMPUTER ENGINEERING DEPARTMENT MRS.S.S.GHULE
2) Left Outer Join 1/2 M each
3) Right Outer Join
4) Full Outer Join
5) Cross Join
6) Self Join
3 Explain pattern matching operators like; and range searching W-23 4
operator ‘between’ with example
Like operator: Proper
The LIKE operator is used to compare a value to similar values Explanation
using wildcard operators. 1 M each,
It uses two wild characters as ‘%’ and ‘_’ where ‘%’ represents Example 1
all characters of the M each
pattern and ‘_’ represents one single character from pattern.
Eg :
Select ename from emp where ename like ‘S%’;
This will return all employee names starting with ‘S’.
Select ename from emp where ename like ‘_a%;
This will return all employee names whose second character is
‘a’.
Between operator: The BETWEEN operator is used to search
for values that are within a
set of values, given the minimum value and the maximum
value inclusive of both the
limits.
Eg: select * from emp where salary between 40000 and 50000;
This will results in rows from emp table where salary falls in
the range
of 40000 to 50000.
4 Explain commit and rollback with syntax and example W-23 4
Commit: Commit:
The COMMIT command saves all transactions to the database Description
since the last COMMIT or and syntax –
ROLLBACK command. 1M
If you want to save all the commands which are executed in a example
transaction, then just after 1M
completing the transaction, you have to execute the commit
command. This command will
save all the commands which are executed on a table.
Furthermore, once the commit command is executed in the
database, we cannot regain its
previous states in which it was earlier before the execution of
the first statement. Rollback:
The syntax: SQL> COMMIT; Description
Or and syntax –
COMMIT WORK; 1M
Example: example
SQL>Commit; 1M
Rollback
The ROLLBACK command is used to undo transactions that
have not already been saved

56
RSCOEP COMPUTER ENGINEERING DEPARTMENT MRS.S.S.GHULE
to the database.
The ROLLBACK command can only be used to undo
transactions since the last
COMMIT or ROLLBACK command was issued.
The syntax for ROLLBACK is:
ROLLBACK TO SAVEPOINT_NAME;
OR
ROLLBACK;
OR
ROLLBACK WORK;
Example:
SQL>ROLLBACK;
5 Write and explain create, update and drop view commands W-23 4
A view is a Virtual Table that is based on the result set of an Create
SQL query. command
Create View: 2M (syntax
A view is created with the CREATE VIEW statement. 1M,
Syntax: explanation
Create view view_name As ½ M,
Select column1, column2… example ½
From table_name M)
Where condition; Update
Example command
Create view mumbai_customers AS 1M (syntax
Select customer_name, contact_name ½ M,
From customers example ½
Where city=’Mumbai’; M)
Update View: Drop1M
A view can be updated with the CREATE OR REPLACE (syntax
VIEW statement. ½ M,
Syntax: example ½
CREATE OR REPLACE VIEW view_name AS M)
SELECT column1, column2, ...
FROM table_name WHERE condition;
Example:
The following SQL adds the "City" column to the "USA
Customers" view:
CREATE VIEW [USA Customers] AS
SELECT CustomerID, CustomerName, City
FROM Customers WHERE Country = ‘USA’;
Drop view:
A view can be deleted with the DROP VIEW statement.
Syntax:
DROP VIEW view_name;
Example:
DROP VIEW [USA Customers];
6 Explain cursor with syntax for declaring ,opening and closing W-23 4
a cursor

57
RSCOEP COMPUTER ENGINEERING DEPARTMENT MRS.S.S.GHULE
A cursor is a temporary work area created in system memory Cursor
when an SQL statement is executed. A cursor is a set of rows Explanation
together with a pointer that identifies a current row. It 1M
is a database object to retrieve data from result set on row at a Declaration
time. Implicit cursor: these types of cursors are generated and of cursor
used by the system during the manipulation of a DML query. 1M
An implicit cursor is also generated by the system when a Open cursor
single row is selected by a SELECT command. Programmers 1M
cannot control the implicit cursors. Closing
Explicit cursor: this type of cursor is created by the user when cursor 1M
the select command returns more than one row, and only one
row is to be processed at a time. An explicit
cursor can move from one row to another in a result set. An
explicit cursor uses a pointer that holds the record of a row.
1) Declaring cursor:
It defines the cursor with a name and the associated SELECT
statement.
Syntax
CURSOR name IS SELECT statement;
2) Open the cursor: It is used to allocate memory for the cursor
and make it easy to fetchthe rows returned by the SQL
statements into it.
Syntax
OPEN cursor_name;
3) Close the cursor:
It is used to release the allocated memory. The following
syntax is used to close the
above-opened cursors.
Syntax:
Close cursor_name;
7 Write the SQL queries for following EMP table. Emp (empno, W-23 6
deptno, ename, salary, designation, city.) i)list employees with
having alphabate ‘A’ as second letter in their name
II) set salary of all project leader to 50,000
III) display average salary of all employess
Iv) display employee-id of employees who live in city ‘pune’
or nagpur
V) Display employee name ,salary and city from ‘hr’
department who having salary greater than 70,000
Vi)display details of all employee who’s salary same as that of
salary of shashank
1. select * from Emp where emp_name like ‘_A%’; 1M each
2. update Emp set salary=50000 where designation=’project
leader’;
3. select avg(salary) from Emp;
4. select emp_id from Emp where city= ‘Pune’ or
city=’Nagpur’;
5. select emp_name,salary,city from Emp where dept=’HR’
and salary > 70000;

58
RSCOEP COMPUTER ENGINEERING DEPARTMENT MRS.S.S.GHULE
6. select * from Emp where salary in (select salary from Emp
where
emp_name=’Shashank’);
8 Consider following schema: W-23 6
Bookmaster (bookid,bookname,author,no _of copies,price)
write down sql queries for following :
I) Write a query to create table Book _master table
II) Write a command to create composite Index on book master
table
III) Write a command to drop above index
IV) Display all books whose number of copies are less than 10
V) Display all books whose price is above rs 700
VI) Create synoym for relation book master as book
information
1. create table Book_Master(book_id number(4,0), book_name 1M each
varchar(50), author
varchar(50), no_of_copies(2,0), price number(6,2));
2. create index composite_book_master on
Book_Master(book_id, book_name);
3. drop index composite_book_master;
4. select book_name,author from Book_Master order by price
desc;
5. select * from Book_Master where no_of_copies >50;
6. create or replace public synonym Book_Information for
Book_Master;
9 Write a command to create table Customer (Custo_id, W-23 6
Cust_name, address, Contact_no, City). And write down the
queries for the following: i) Insert one row into table. ii) Save
the data. iii) Insert Second row into the table. iv) Create save
point S1. v) Insert one row into the table
1. create table Customer(Custo_id number(2,0), Cust_name 1 M each
varchar(30), address
varchar(50), Contact_no varchar(10), city varchar(30));
2. insert into Customer values(1,’Ramesh’,’Ganesh Peth’,
‘9123456780’,’Pune’);
3. commit;
4. insert into Customer values (2,’Suresh’,’Sadashiv Peth’,
‘8123456790’,’Pune’);
5. savepoint s1;
6. insert into Customer values (3,’Rajesh’,’Shukrawar Peth’,
‘8912345670’,’Pune’);

1 List date and time function S-24 2


ADDTIME(exp1,exp2) This function adds the two expressions
exp1 and exp2 and displays the result. ...
CURTIME() This returns the current time of the system from
the current time zone in the format HH:MM:SS. ...
DAYOFMONTH(date) ...
MONTH(date)
2 Explain any set operators in SQL with example. S-24 4
59
RSCOEP COMPUTER ENGINEERING DEPARTMENT MRS.S.S.GHULE
Set operators combine the results of two component queries
into a
single result. Queries containing set operators are called as
compound
queries. Set operators in SQL are represented with following
special
keywords as: Union, Union all, intersection & minus.
1) Union: The Union of two or more sets contains all elements,
which are present in either or both. Union works as or. The
duplicates
of both the tables will appear only once.
E.g. select ename from emp1 union select ename from emp2;
2) Union all: The Union of 2 or more sets contains all elements,
which are present in both, including duplicates.
E.g. select ename from emp1 union all select ename from
emp2;
3) Intersection: The intersection of two sets includes elements
which
are present in both.
E.g. select ename from emp1 intersect select ename from
emp2;
4) Minus: The minus of two sets includes elements from set1
minus
elements of set2.
E.g. select ename from emp1 minus select ename from emp2
3 Write a query using group by clause(use student database) S-24 4
The GROUP BY Statement in SQL is used to arrange identical
data into groups with the help of some functions. i.e. if a
particular column has the same values in different rows then it
will arrange these rows in a group.

Features
GROUP BY clause is used with the SELECT statement.
In the query, the GROUP BY clause is placed after the
WHERE clause.
In the query, the GROUP BY clause is placed before the
ORDER BY clause if used.
In the query, the Group BY clause is placed before the Having
clause.
Place condition in the having clause.
Syntax:

SELECT column1, function_name(column2)

FROM table_name
WHERE condition

GROUP BY column1, column2

ORDER BY column1, column2;

60
RSCOEP COMPUTER ENGINEERING DEPARTMENT MRS.S.S.GHULE
CREATE TABLE student (
name VARCHAR(50),
year INT,
subject VARCHAR(50)
);
INSERT INTO student (name, year, subject) VALUES
('Alice', 1, 'Mathematics'),
('Bob', 2, 'English'),
('Charlie', 3, 'Science'),
('David', 1, 'Mathematics'),
('Emily', 2, 'English'),
('Frank', 3, 'Science')

4 Write and explain syntax for creating and dropping synonyms S-24 4
with example
A synonym is an alternative name for objects such as tables,
views, sequences, stored procedures, and other database
objects.
You generally use synonyms when you are granting access to
an object from another schema and you don't want the users to
have to worry about knowing which schema owns the object.
Create Synonym (or Replace)
You may wish to create a synonym so that users do not have to
prefix the table name with the schema name when using the
table in a query.

Syntax
The syntax to create a synonym in Oracle is:
CREATE [OR REPLACE] [PUBLIC] SYNONYM [schema .]
synonym_name
FOR [schema .] object_name [@ dblink];
OR REPLACE
Allows you to recreate the synonym (if it already exists)
without having to issue a DROP synonym command.
PUBLIC
It means that the synonym is a public synonym and is
accessible to all users. Remember though that the user must
first have the appropriate privileges to the object to use the
synonym.
schema
The appropriate schema. If this phrase is omitted, Oracle
assumes that you are referring to your own schema.
object_name
The name of the object for which you are creating the synonym.
It can be one of the following:
table
view
sequence
stored procedure
function

61
RSCOEP COMPUTER ENGINEERING DEPARTMENT MRS.S.S.GHULE
package
materialized view
java class schema object
user-defined object
synonym
Example
Let's look at an example of how to create a synonym in Oracle.

For example:

CREATE PUBLIC SYNONYM suppliers


FOR app.suppliers;
This first CREATE SYNONYM example demonstrates how to
create a synonym called suppliers. Now, users of other schemas
can reference the table called suppliers without having to prefix
the table name with the schema named app. For example:

SELECT *
FROM suppliers;
If this synonym already existed and you wanted to redefine it,
you could always use the OR REPLACE phrase as follows:

CREATE OR REPLACE PUBLIC SYNONYM suppliers


FOR app.suppliers;
Drop synonym
Once a synonym has been created in Oracle, you might at some
point need to drop the synonym.

Syntax
The syntax to drop a synonym in Oracle is:

DROP [PUBLIC] SYNONYM [schema .] synonym_name


[force];

5 Difference between delete and truncate command with S-24 4


example

62
RSCOEP COMPUTER ENGINEERING DEPARTMENT MRS.S.S.GHULE
6 Explain any four joins if SQL Example S-24 4
JOIN:
A SQL join is an instruction to combine data from two sets of
data (i.e. two
tables). A JOIN clause is used to combine rows from two or
more tables, based on a related column between them. SQL
Join types are as follows:
1) EQUI JOIN:
A join which is based on equalities is called equi join. In equi
join comparison
operator “=” is used to perform a Join.
Syntax:
SELECTtablename.column1_name,tablename.column2_name
FROM table_name1,table_name2
Where
table_name1.column_name=table_name2.column_name;
Example:
Select stud_info.stud_name, stud_info.branch_code,
branch_details.location
From stud_info, branch_details
Where Stud_info.branch_code=branch_details.branch_code;
2) SELF JOIN:
The SQL SELF JOIN is used to join a table to itself, as if the
table were two

63
RSCOEP COMPUTER ENGINEERING DEPARTMENT MRS.S.S.GHULE
tables,temporarily renaming at least one table in the SQL
statement.
Syntax:
SELECT a.column_name, b.column_name
FROM table1 a, table1 b
WHERE a.common_filed = b.common_field;
Example:
Select x.stud_name, y.stud_name
from stud_info x, stud_info y
Where x.leader= y.stud_id;
3) INNER JOIN:The INNER JOIN command returns rows that
have
matching values in both tables.
Syntax:
Select column1_name,column2_name
from table1name INNER JOIN table2name
on table1name.columnname= table2name.columnname;
Example:
Select last_name, department_name
from employees inner join departments
on employees.department_id = departments.department_id;
4) LEFT OUTER JOIN:
A left outer join retains all of the rows of the “left” table,
regardless of whether
there is a row that matches on the “right” table.
Syntax:
Select column1_name,column2_name
from table1name any_alias1 ,table2name any_alias2
on any_alias1.columnname(+) = any_alias2.columnname;
OR
Select column1_name,column2_name
from table1name left outer join table2name
on table1name.columnname= table2name.columnname;
Example:
select last_name, department_name
from employees e, departments d
on e.department_id(+) = d.department_id;
OR
select last_name, department_name
from employees left outer join departments
on employees.department_id = departments.department_id;
5) RIGHT OUTER JOIN:
A right outer join retains all of the rows of the “right” table,
regardless of
whether there is a row that matches on the “left” table.
Syntax:
Select column1name, column2name
from table1name any_alias1, table2name any_alias2
on any_alias1.columnname =any_alias2.columnname (+);
OR

64
RSCOEP COMPUTER ENGINEERING DEPARTMENT MRS.S.S.GHULE
Select column1name, column2name
from table1name any_alias1 right outer join table2 name
any_alias2
on any_alias1.columnname =any_alias2.columnname;
7 I) Write a query to create table emp- S-24 6
details(EMP_ID,name,dept) with proper data types and
Emp_ID as primary key and name as NOT NULL constrain
II) Perform all DML command on above created table

8 Create simple and composite index write command to drop S-24 6


index
CREATE INDEX
The CREATE INDEX command is used to create indexes in
tables. It allows
duplicate values. Indexes are used to retrieve data from the
database very fast. The
users cannot see the indexes; they are just used to speed up
searches/queries.
Syntax:
CREATE INDEX index_name
ON table_name (column1, column2, ...);
Example:
The following SQL creates an index named id_firstname on the
FirstName column in
the Student table:
CREATE INDEX id_firstname
ON Student (FirstName);
DROP INDEX
The DROP INDEX statement is used to delete an index in a
table.
Syntax:
DROP INDEX index_name ON table_name;
Example:
DROP INDEX id_firstname ON Student;
9 Consider following schema: S-24 6
Bookmaster (bookid,bookname,author,no _of copies,price)
write down sql queries for following :
VII) Write a command to create Boo _master table
65
RSCOEP COMPUTER ENGINEERING DEPARTMENT MRS.S.S.GHULE
VIII) Increase the price of all books by 20%
IX) Display all books whose price ranges from rs 500 to rs 800.
X) Display all books whose number of copies are less than 10
XI) Display all books whose price is above rs 700
XII) Display all books with details whose name start with ‘D’.

10 S-24 6
WRITE SQL COMMAND FOR Following
I) Create user
II) Grant privileges to user
III) Remove privileges to user
i) Create user
CREATE USER <username> IDENTIFIED BY <password>;
(OR)
CREATE USER RAJ IDENTIFIED BY RAJ123;
ii) Grant privileges to user.
GRANT <privilege list> ON <relation name or view name>
TO<user list>;
(OR)
(assuming table Employee for granting permissions to user
‘RAJ’
for select, insert, update and delete privilege)
GRANT SELECT, INSERT,UPDATE,DELETE ON
EMPLOYEE TO RAJ;
Iii) Remove privileges from user.
REVOKE <privilege list> ON <relation name or view name >
FROM <user list>;
(OR)
66
RSCOEP COMPUTER ENGINEERING DEPARTMENT MRS.S.S.GHULE
67
RSCOEP COMPUTER ENGINEERING DEPARTMENT MRS.S.S.GHULE
JSPM’s
RAJARSHI SHAHU COLLEGE OF ENGINEERING,
POLYTECHNIC
Department of Computer Engineering
Academic Year: 2024-25

UNIT-4 ( 18Marks)
MSBTE Question bank

Sr.No. Question Year Marks

1 Define cursor. List the two types of cursor W-18, 2


W-23
Cursor: The Oracle Engine uses a work area for its internal
processing in order to
execute an SQL statement. This work area is private to SQL‟s
operations and is called a
Cursor.
OR
A cursor is a temporary work area created in the system memory
when a SQL statement
is executed.
Types of cursor are:
1) Implicit cursor
2) Explicit cursor

2 Describe exception handling in brief. W-18, 4


S-19

68
RSCOEP COMPUTER ENGINEERING DEPARTMENT MRS.S.S.GHULE
Exception Handling: Exception is nothing but an error. Exception
can be raise when
DBMS encounters errors or it can be raised explicitly.
When the system throws a warning or has an error it can lead to an
exception. Such
exception needs to be handled and can be defined internally or user
defined.
Exception handling is nothing but a code block in memory that will
attempt to resolve
current error condition.
Syntax:
DECLARE ;
Declaration section
…executable statement;
EXCEPTION
WHEN ex_name1 THEN ;
Error handling statements/user defined action to be carried out;
END;
Types of Exception:
1) Predefined Exception/system defined exception/named
exception: Are always
automatically raised whenever related error occurs. The most
common errors that can
occur during the execution of PL/SQL. Not declared explicitly i.e.
cursor already open,
invalid cursor, no data found, zero divide and too many rows etc.
Programs are handled
by system defined Exceptions.
2) User defined exception: It must be declare by the user in the
declaration part of the
block where the exception is used. It is raised explicitly in
sequence of statements using:
Raise_application_error(Exception_Number, Error_Message);
3 Explain function PL\SQL with example W-18 4
Function: Description:
Function is a logically grouped set of SQL and Pl/SQL statements 2
that perform a marks,
specific task. A function is same as a procedure except that it Example : 2
returns a value. A marks
function is created using the CREATE FUNCTION statement.
Syntax:
CREATE [OR REPLACE] FUNCTION function_name
[(parameter_name [IN | OUT | IN OUT] type [, ...])]
RETURN return_datatype
{IS | AS}
BEGIN
< function_body >
END [function_name];
Where,
-name specifies the name of the function.

69
RSCOEP COMPUTER ENGINEERING DEPARTMENT MRS.S.S.GHULE
function.

the parameters. IN
represents the value that will be passed from outside and OUT
represents the
parameter that will be used to return a value outside of the
procedure.
tain a return statement.

return from the


function.
-body contains the executable part.

a standalone
function.
Example:
CREATE OR REPLACE FUNCTION Success_cnt
RETURN number
IS cnt number(7) := 0;
BEGIN
SELECT count(*) into cnt
FROM candidate where result='Pass';
RETURN cnt;
END;
/
4 Draw the block structure of PL/SQL . List advantages of PL/SQL W-18 4

70
RSCOEP COMPUTER ENGINEERING DEPARTMENT MRS.S.S.GHULE
Advantages of PL/SQL:
1. PL/SQL is portable and high transaction processing language.
2. PL/SQL is in fact procedural language but it also supports object
oriented
programming.
3. It allows user to write as well as access the functions and
procedures from outside the
programs.
4. It has got built in libraries of packages

5 Write step by step syntax to create, open and close cursor in W-18, 4
PL/SQL. S-23
A cursor holds the rows (one or more) returned by a SQL 2 marks,
statement. Opening: 1
Declaring: This term is used to declare a cursor so that memory mark,
initialization will take place.A cursor is declared by defining the Closing
SQL statement that returns a result set. cursor: 1
Example: mark
Declare CURSOR Winter_18 IS SELECT roll_no, std_name,
percentage FROM
student;
Opening: A Cursor is opened and populates data by executing the
SQL statement defined by the cursor.
Example:
Open Winter_18;
Closing a Cursor: This forces cursor for releasing the allocated
memory assigned/ occupied by cursor.
Example:
CLOSE Winter_18;
6 Write a PL/SQL program which accept the customer ID from the W-18 6
user if user enters an invalid ID then the exception invalid_id is
raised using exception handling.

71
RSCOEP COMPUTER ENGINEERING DEPARTMENT MRS.S.S.GHULE
DECLARE
c_id numeric(10);
invalid_id_Exception Exception;
BEGIN
c_id:=&c_id;
if(c_id<0) then
raise invalid_id_Exception;
end if;
EXCEPTION
WHEN invalid_id_Exception THEN
dbms_output.put_line('Invalid customer id');
END;
1 State any four PL/SQL data types. S-19 2
1. NUMBER or NUMBER(P,S)
2. PLS_INTEGER
3. CHAR
4. RAW
5. ROWID
6. VARCHAR2
7. DATE
2 Explain PL/SQL block structure with the help of diagram S-19, 4
S-22

Declaration section
A block begins with declarative section where variables, cursors
are declared. It is an Optional block.
Execution section
Executable SQL or PL/SQL Statements are needed to write here
for the execution. It is mandatory block.
Exception section
It is used to handles the exceptions. It is an Optional block.
End statement
It is used to indicate termination of PL/SQL block. It is mandatory
3 Explain cursor with example S-19 4

72
RSCOEP COMPUTER ENGINEERING DEPARTMENT MRS.S.S.GHULE
A cursor is a temporary work area created in system memory when
a SQL statement is executed. A cursor is a set of rows together with
a pointer that identifies a current row. It is a database object to
retrieve data from a result set one row at a time. It is useful when we
want to manipulate the record of a table in a singleton method, in
other wordsone row at a time. In other words, a cursor can hold
more than one row, but can process only one row at a time. The set
of rows the cursor holds is called the active set.
Each cursor contains the followings 4 steps,
1. Declare Cursor: In this part we declare variables and return a set
of values.
2. Open: This is the entering part of the cursor.
3. Fetch: Used to retrieve the data row by row from a cursor.
4. Close: This is an exit part of the cursor and used to close a
cursor.
5. Eg:
Declare
enumemp.eno%type;
enemp.ename%type;
Cursor cur is select eno, ename from emp where jobname = “mgr”;
Begin
Open cur;
Loop Fetch cur into enum,en;
Exit when cur%NOTFOUND;
Dbms_output.put_line(„emp num ‟||enum||‟ emp name „||en);
End loop;
Close cur;
End; /
The example shows fetching multiple records using cursor. A
cursor is a temporary work area created in system memory when a
SQL
statement is executed. A cursor is a set of rows together with a
pointer that identifies a current row.
In the example, the cursor is defined to hold the rows as defined by
the select query. Once the cursor is defined, the next step is to open
the cursor. When the cursor is opened, it is ready to retrieve the
rows. This is done using the fetch statement. Since there are many
rows, a loop is used to display the values of all the rows.
Once the rows are fetched, the
cursor should be closed.
4 State the use of database trigger and also list types of trigger S-19 4
Use of trigger
Trigger: A trigger is a stored procedure in database which
automatically
invokes whenever a special event in the database occurs. A trigger
can be invoked when a row is inserted into a specified table or
when certain table columns are being updated.
Triggers are written to be executed in response to any of the
following

73
RSCOEP COMPUTER ENGINEERING DEPARTMENT MRS.S.S.GHULE
events − A database manipulation (DML) statement (DELETE,
INSERT, or
UPDATE)
Database definition (DDL) statements (CREATE, ALTER, or
DROP).
A database operation (SERVERERROR, LOGON, LOGOFF,
STARTUP, or SHUTDOWN).
Triggers can be defined on the table, view, schema, or database
with
which the event is associated.
Triggers can be written for the following purposes –

referential integrity

Types of trigger

s
5 Write a PL/SQL program to calculate factorial of a given number S-19 6
DECLARE
num number:=&num;
fact number:=1;
BEGIN
while num!=0
loop
fact:=fact*num;
num:=num-1
end loop;
dbms_output.put_line(‘Factorial =’||fact);
END;
/
(OR)
DECLARE
num number:=&num;
fact number:=1;
i number;
BEGIN
for i in 1..num loop
fact:=fact*i;
end loop;

1 State any two advantages of functions in PL/SQL. W-19, 2


S-22,
W-22

manageable and also enhances the readability of the code.

74
RSCOEP COMPUTER ENGINEERING DEPARTMENT MRS.S.S.GHULE
database details from the user.

times
2 Explain implicit and explicit cursors W-19 4
A cursor is a temporary work area created in system memory when
an SQL statement is executed. A cursor is a set of rows together
with a pointer that identifies a current row. It is a database object
to retrievedata from result set on row at a time.
Implicit cursor: these types of cursors are generated and used by
the system during the manipulation of a DML query. An implicit
cursor is also generated by the system when a single row is selected
by a SELECT command. Programmers cannot control the implicit
cursors.
Explicit cursor: this type of cursor is created by the user when the
select command returns more than one row, and only one row is to
be
processed at a time. An explicit cursor can move from one row to
another in a result set. An explicit cursor uses a pointer that holds
the
record of a row.
To create an explicit cursor the following steps are used.
1. Declare cursor: this is done in the declaration section of PL/SQL
program.
2. Open: this step is done before the cursor is used to fetch the
records.
3. Fetch: used to retrieve data row by row from the cursor.
4. Close: once the processing of the data is done, the cursor can be
closed
3 Explain Exception handling with it’s types W-19 4
An exception is an error condition during a program execution.
PL/SQL supports programmers to catch such conditions
using EXCEPTION block in the program and an appropriate action
is taken against the error condition.
There are two types of exceptions −
-defined exceptions/Predefined exceptions/Built-in
Exceptions
2) User-defined exception
1) Predefined exceptions- PL/SQL provides predefined Exception,
which are executed when any database rule is violated by a
program.
Example: NO_DATA_FOUND, ZERO_DIVIDE.
Syntax for Predefined Exception Handling:
The general syntax for exception handling is as follows.
DECLARE
<declarations section>
BEGIN
<executable command(s)>
EXCEPTION

75
RSCOEP COMPUTER ENGINEERING DEPARTMENT MRS.S.S.GHULE
<exception handling goes here >
WHEN exception1 THEN
exception1-handling-statements
WHEN exception2 THEN
exception2-handling-statements
WHEN exception3 THEN
exception3-handling-statements
........
WHEN others THEN
exception3-handling-statements
END;
2) User defined Exceptions:
PL/SQL allow us to define our own exception according to the
need
of our program. A user defined exception must be declared and
then
raised explicitly.
Syntax for User defined Exception:
DECLARE
exception_name EXCEPTION;
BEGIN
IF condition THEN
RAISE exception_name;
END IF;
EXCEPTION
WHEN exception_name THEN
statement;
END;
4 Define database trigger. How to create and delete trigger ? W-19 4
Triggers are stored programs, which are automatically executed or
fired when some events occur. Triggers are, in fact, written to be
executed in response to any of the following events −

INSERT, or UPDATE)

DROP).
Triggers can be defined on the table, view, schema, or database
with
which the event is associated.
Creating Triggers
The syntax for creating a trigger is −
CREATE [OR REPLACE ] TRIGGER trigger_name
{BEFORE | AFTER | INSTEAD OF }
{INSERT [OR] | UPDATE [OR] | DELETE}
[OF col_name]
ON table_name
[REFERENCING OLD AS o NEW AS n]
[FOR EACH ROW]
WHEN (condition)
DECLARE

76
RSCOEP COMPUTER ENGINEERING DEPARTMENT MRS.S.S.GHULE
Declaration-statements
BEGIN
Executable-statements
EXCEPTION
Exception-handling-statements
END;
To delete a trigger:
Syntax:
DROP TRIGGER trigger_name.
5 Explain any one control structure in PL/SQL with example W-19 4
PL/SQL has three categories of control statements: conditional
selection statements, loop statements and sequential control
statements.
PL/SQL categories of control statements are:

for different data values.


The conditional selection statements are IF and CASE.
s of
different data values.
The loop statements are the basic LOOP, FOR LOOP,
and WHILE LOOP.The EXIT statement transfers control to the
end of a loop.
The CONTINUE statement exits the current iteration of a loop and
transfers control to the next iteration.
Both EXIT and CONTINUE have an optional WHEN clause,
where you can specify a condition.

programming.
The sequential control statements are GOTO, which goes to a
specified statement, and NULL, which does nothing.
1)Conditional Control: IF and CASE Statements:
The IF statement lets us execute a sequence of statements
conditionally. That is, whether the sequence is executed or not
depends on the value of a condition. There are three forms
of IF statements: IF-THEN, IF-THEN-ELSE, and IF-THEN-
ELSIF.
The CASE statement is a compact way to evaluate a single
condition
and choose between many alternative actions.
IF-THEN Statement:The simplest form of IF statement associates
a
condition with a sequence of statements enclosed by the
keywords THEN and END IF (not ENDIF), as follows:
IF condition THEN
sequence_of_statements
END IF;
IF-THEN-ELSE Statement: The second form of IF statement adds
the keyword ELSE followed by an alternative sequence of
statements,
as follows:

77
RSCOEP COMPUTER ENGINEERING DEPARTMENT MRS.S.S.GHULE
IF condition THEN
sequence_of_statements1
ELSE
sequence_of_statements2
END IF;
IF-THEN-ELSIF Statement: The third form of IF statement uses
the keyword ELSIF (not ELSEIF) to introduce additional
conditions,
as follows:
IF condition1 THEN
sequence_of_statements1
ELSIF condition2 THEN
sequence_of_statements2
ELSE
sequence_of_statements3
END IF;
CASE Statement: Like the IF statement, the CASE statement
selects
one sequence of statements to execute.
IF grade = 'A' THEN
dbms_output.put_line('Excellent');
ELSIF grade = 'B' THEN
dbms_output.put_line('Very Good');
ELSIF grade = 'C' THEN
dbms_output.put_line('Good');
ELSIF grade = 'D' THEN
dbms_output. put_line('Fair');
ELSIF grade = 'F' THEN
dbms_output.put_line('Poor');
ELSE
dbms_output.put_line('No such grade');
END IF;
END CASE;
2) Iterative Control: LOOP and EXIT Statements:
LOOP statements let us execute a sequence of statements multiple
times. There are three forms of LOOP statements: LOOP,
WHILELOOP, and FOR-LOOP.
LOOP: The simplest form of LOOP statement is the basic (or
infinite) loop, which encloses a sequence of statements between
the
keywords LOOP and END LOOP, as follows:
LOOP
sequence_of_statements
END LOOP;
WHILE-LOOP:The WHILE-LOOP statement associates a
condition with a sequence of statements enclosed by the
keywords LOOP and END LOOP, as follows:
WHILE condition LOOPsequence_of_statements
END LOOP;
Before each iteration of the loop, the condition is evaluated. If the

78
RSCOEP COMPUTER ENGINEERING DEPARTMENT MRS.S.S.GHULE
condition is true, the sequence of statements is executed, then
control resumes at the top of the loop. If the condition is false or
null, the
loop is bypassed and control passes to the next statement.
FOR-LOOP:Whereas the number of iterations through
a WHILE loop is unknown until the loop completes, the number
of iterations through a FOR loop is known before the loop is
entered. FOR loops iterate over a specified range of integers. The
range is part of an iteration scheme, which is enclosed by the
keywords FOR and LOOP. A double dot (..) serves as the range
operator. The syntax follows:
FOR counter IN [REVERSE] lower_bound..higher_bound LOOP
sequence_of_statements
END LOOP.
6 Write a PL/SQL program to print n even numbers using For Loop W-19 6
declare Correct
num number; logic 3M
n number:=&n; Correct
begin syntax
for num in 1..n loop 3M
if(mod(num,2)=0) then
dbms_output.put_line(‘Even no are :’||num);
end if;
end loop;
end;

1 Explain conditional control in PL/SQL with example. S-22 4


In many case we would be in a state whether we have to choose
Yes or No. These types of questions are also called Decision
Statements. Here, the user is compelled to choose one answer. In
this case we choose the answer based on the condition in which we
are present. In the same way, Every Program has its moments like
choosing if this condition is positive then we choose Yes statement
else if condition is false then we choose No statement while coding.
The Every Programming Language has a few Conditional
statements. These Conditional statements are also known as
Decision Statements. There are a few Conditional Statements or
Decision Statements in PL / SQL (Procedure Language /
Structured Query Language).
The Conditional Statements can only be used in BEGIN State.

Types of Conditional Statements


if condition then statement
if condition then else statement
nested if condition then statements
if condition then elseif condition then else statements
1.) if Condition then Statement
This is one of the first important PL / SQL Conditional Statement.
In this statement only if the condition is true, then the output is

79
RSCOEP COMPUTER ENGINEERING DEPARTMENT MRS.S.S.GHULE
going to be shown. Else in any other cases there is no opportunity
for outputs.
Syntax

IF <condition> then
Statement 1
Statement 2
.
.
.
.
Statement N
END IF;
Example Queries

SQL> DECLARE
2 N1 INTEGER;
3 BEGIN
4 N1:=10;
5 IF N1 > 10 THEN
6 dbms_output.put_line('The Value is' || N1);
7 END IF;
8 END;
9/
OUTPUT:

PL/SQL procedure successfully completed.


2 Write and explain syntax for creating Trigger S-22 4
Triggers are stored programs, which are automatically executed or
fired when some events occur. Triggers are, in fact, written to be
executed in response to any of the following events −

INSERT, or UPDATE)

DROP).
Triggers can be defined on the table, view, schema, or database
with
which the event is associated.
Creating Triggers
The syntax for creating a trigger is −
CREATE [OR REPLACE ] TRIGGER trigger_name
{BEFORE | AFTER | INSTEAD OF }
{INSERT [OR] | UPDATE [OR] | DELETE}
[OF col_name]
ON table_name
[REFERENCING OLD AS o NEW AS n]
[FOR EACH ROW]
WHEN (condition)
DECLARE
Declaration-statements

80
RSCOEP COMPUTER ENGINEERING DEPARTMENT MRS.S.S.GHULE
BEGIN
Executable-statements
EXCEPTION
Exception-handling-statements
END;
To delete a trigger:
Syntax:
DROP TRIGGER trigger_name.
3 Write a PL/SQL program, which accept the number from user. If S-22 6
user enters an odd number then exception invalid number is raised
using user defined exception handling.
DECLARE
v_input VARCHAR2(10) := 'abc';
v_number NUMBER;
BEGIN
BEGIN
v_number := TO_NUMBER(v_input);
DBMS_OUTPUT.PUT_LINE('Conversion successful.
Number: ' || v_number);
EXCEPTION
WHEN INVALID_NUMBER THEN
DBMS_OUTPUT.PUT_LINE('Error: Invalid number');
END;
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('Error: ' || SQLERRM);
END;

1 Write a PL/SQL code to print reverse of a number. W-22 4


declare
n number;
i number;
rev number:=0;
r number;
begin
n:=&n;
while n>0
loop
r:=mod(n,10);
rev:=(rev*10)+r;
n:=trunc(n/10);
end loop;
dbms_output.put_line('reverse is '||rev);
end;
2 Explain the steps of cursor implementation with syntax and W-22 4
example
a. Declaring cursor:
Cursor is declared in the declaration section.
Syntax: cursor <cursor_name>is<select query>;
Ex: cursor a is select ename from emp_details where empno=3;
81
RSCOEP COMPUTER ENGINEERING DEPARTMENT MRS.S.S.GHULE
b. Opening cursor:
After declaring the cursor, the cursor needs to open.
Syntax: open <cursor_name>;
Ex: open a;
c. Fetching a record from cursor:
Once the cursor is declared and opened, we need to get records or
rows from
the cursor. These records are accessed using the FETCH statement.
Syntax: fetch <cursor_name> into <variable_list>;
Ex: fetch a into name;
d. Closing cursor:
Once the cursor is opened and processing is over, we need to close
it.
Syntax: close <cursor_name>;
Ex: close a;
Example:
declare
name emp_details.ename%type;
cursor a is select ename from emp_details where empno=3;//cursor
declaration
begin
open a;//opening the cursor
loop
fetch a into name;//fetching the rows from cursor
update emp_details set comm=3000 where empno=3;
exit when a%notfound;
dbms_output.put_line('record updated');
end loop;
close a;//closing the cursor
end;
3 Write and Explain the syntax for creating database trigger W-22 4
Database trigger:
Triggers can be referred as stored procedures that are fired or
executed when an
INSERT, UPDATE or DELETE statement is given against the
associated table.
Syntax:
create trigger [trigger_name]
[before | after]
{insert | update | delete}
on [table_name]
[for each row]
[trigger_body]
Explanation of syntax:
1. create trigger [trigger_name]: Creates or replaces an existing
trigger with the
trigger_name.
2. [before | after]: This specifies when the trigger will be executed.
3. {insert | update | delete}: This specifies the DML operation.

82
RSCOEP COMPUTER ENGINEERING DEPARTMENT MRS.S.S.GHULE
4. on [table_name]: This specifies the name of the table associated
with the trigger.
5. [for each row]: This specifies a row-level trigger, i.e., the trigger
will be executed
for each row being affected.
6. [trigger_body]: This provides the operation to be performed as
trigger is fired
Example:
Given Student Report Database, in which student marks
assessment is recorded. In
such schema, create a trigger so that the total and percentage of
specified marks is
automatically inserted whenever a record is insert.
Here, as trigger will invoke before record is inserted so, BEFORE
Tag can be used.
create trigger stud_marks
before INSERT
on
Student
for each row
set Student.total = Student.subj1 + Student.subj2 + Student.subj3,
Student.per
= Student.total * 60 / 100;
4 Write a trigger which invokes on deletion of record on emp table W-22 4
Delete Trigger: 4M
create or replace trigger trg1 before delete on emp_details Or any other
declare correct logic
begin for delete
raise_application_error(-20000,'cannot delete the record'); trigger
end
5 Write a PL/SQL code to check whether specified employee is W-22 6
present in Emp table or not. Accept empno from user. If employee
does not exist display message using exception handling.
PL/SQL Program: 2M
declare =declaration
no emp.empno%type; 2M=select
begin statement
no:=&no; 2M=proper
select empno into no from emp where empno=no; exception
dbms_output.put_line('Empno is present: '||no); message
exception
when no_data_found then
dbms_output.put_line('Empno not present');
end;

1 Draw block structure of PL/SQL. S-23 2

83
RSCOEP COMPUTER ENGINEERING DEPARTMENT MRS.S.S.GHULE
2 State syntax of while loop command S-23 2
Syntax :
WHILE <condition>
LOOP statements;
END LOOP;
3 Explain subquery concept with example S-23 2
Subquery : A subquery is a query which is embedded within Explanati
another query. The outer query is called as main query and inner on 1M
query is called as subquery Example
For Example: 1M
Select * from customer where age = ( Select min(age) from
customer );
The above query will select all rows from customer table with
minimum age.
4 Explain trigger with suitable example S-23 4
Trigger: Correct
Triggers are stored programs, which are automatically executed or explanati
fired when some events occur. Triggers are, in fact, written to be on 2M
executed in response to any Any
of the following events - relevant
example
or UPDATE) 2M

DROP).
Triggers can be defined on the table, view, schema, or database
with which the
event is associated. a
For Example:
create trigger trigger_update
on emp
after update
as begin Select * from employee;
end;

84
RSCOEP COMPUTER ENGINEERING DEPARTMENT MRS.S.S.GHULE
The above trigger will invoke after update of record in emp table.
5 Write a pl sql program to print odd number from 1to 10 S-23 4
begin 2M for
dbms_output.put_line(„Oddnos from 1 to 10 are :‟); Correct
fornum in 1..10 Logic
loop 2M for
if(mod(num,2)!=0) then correct
dbms_output.put_line(num); syntax
end if;
end loop;
end;
6 Explain for loop syntax in PLSQL with suitable example of S-23 6
printing 10 to 1 reverse number
For Loop :

execute a
sequence of statements once for each integer in the range.

FOR counter IN lower_bound..upper_bound LOOP


<loop_body><loop body/statements>
END LOOP;
(OR)
For counter IN [reverse] lower_bound..upper_bound LOOP
<loop body/statements>;
END LOOP;
Program:
declare
a number(2);
begin
for a in reverse 1..10 loop
dbms_output.put_line(„value of a :‟ || a);
end loop;
end;
/
7 Explain function in PL-SQL with suitable Example S-23 6
Function: Function is a logically grouped set of SQL and PL/SQL 3M for
statements that Explanati
perform a specific task. A function is same as a procedure except on
that it returns a 3M for
value. A function is created using the CREATE FUNCTION Example
statement.
Syntax:
CREATE [OR REPLACE] FUNCTION function_name
[(parameter_name [IN | OUT | IN OUT] type [, ...])]
RETURN return_datatype
{IS | AS}
BEGIN
< function_body >
END [function_name];
85
RSCOEP COMPUTER ENGINEERING DEPARTMENT MRS.S.S.GHULE
Where,
-name specifies the name of the function.
dification of an existing
function.

the parameters.
IN
represents the value that will be passed from outside and OUT
represents the
parameter that will be used to return a value outside of the
procedure.

return from the


function.
-body contains the executable part.
ing
a standalone
function.
Example:
CREATE OR REPLACE FUNCTION Success_cnt
RETURN number
IS cnt number(7) := 0;
BEGIN
SELECT count(*) into cntFROM candidate where result='Pass';
RETURN cnt;
END; /
Note: Any other example can be considered.

1 Describe exception handling in PL/SQL W-23 4


Exception handling in PL/SQL:
An exception is an error condition during a program execution.
PL/SQL supports
programmers to catch such conditions using EXCEPTION block
in the program and an
appropriate action is taken against the error condition.
There are two types of exceptions −
1) System-defined exceptions/Predefined exceptions/Built-in
Exceptions
2) User-defined exception
1) Predefined exceptions- PL/SQL provides predefined Exception,
which are executed
when any database rule is violated by a program.
Example: NO_DATA_FOUND, ZERO_DIVIDE.
Syntax for Predefined Exception Handling:
The general syntax for exception handling is as follows.
DECLARE
<declarations section>
BEGIN
<executable command(s)>

86
RSCOEP COMPUTER ENGINEERING DEPARTMENT MRS.S.S.GHULE
EXCEPTION
<exception handling goes here >
WHEN exception1 THEN
exception1-handling-statements
WHEN exception2 THEN
exception2-handling-statements
WHEN exception3 THEN
exception3-handling-statements
........
WHEN others THEN
exception3-handling-statements
END;
2) User defined Exceptions:
PL/SQL allow us to define our own exception according to the
need of our program. A
user defined exception must be declared and then raised explicitly.
Syntax for User defined Exception:
DECLARE
exception_name EXCEPTION;
BEGIN
IF condition THEN
RAISE exception_name;
END IF;
EXCEPTION
WHEN exception_name THEN
statement;
END;
Example:
DECLARE
A number:=20;
B number:=0;
C number;
BEGIN
dbms_output.put_line(‘First Num : ’||A);
dbms_output.put_line(‘Second Num : ’||B);
C:= A / B;
--Raise built in Exception if B is 0
dbms_output.put_line(‘ Result ’ || C);-- and then Result will not be
displayed
EXCEPTION
WHEN ZERO_DIVIDE THEN
dbms_output.put_line(‘ Trying to Divide by zero :: Error ’);
END;
2 Explain procedures in PL\SQL with example W-23 4
(any relevant example should be considered)
The PL/SQL stored procedure or simply a procedure is a PL/SQL
block which performs one or more specific tasks. It is just like
procedures in other programming languages.
The procedure contains a header and a body. Header: The header
contains the name of the procedure and the parameters or

87
RSCOEP COMPUTER ENGINEERING DEPARTMENT MRS.S.S.GHULE
variables passed to the procedure.Body: The body contains a
declaration section, execution section and exception
section similar to a general PL/SQL block.When you want to
create a procedure or function, you have to define parameters.
There is
three ways to pass parameters in procedure:
1. IN parameters: The IN parameter can be referenced by the
procedure or function
The value of the parameter cannot be overwritten by the
procedure or the function.
2. OUT parameters: The OUT parameter cannot be
referenced by the procedure or
function, but the value of the parameter can be overwritten
by the procedure or
function.
3. INOUT parameters: The INOUT parameter can be
referenced by the procedure
or function and the value of the parameter can be
overwritten by the procedure or
function.
PL/SQL Create Procedure
Syntax for creating procedure:
CREATE [OR REPLACE] PROCEDURE
procedure_name
[ (parameter [,parameter]) ]
IS
[declaration_section]
BEGIN
executable_section
[EXCEPTION
exception_section]
END [procedure_name];
Example:
The following example creates a simple procedure that
displays the string 'Hello World!'
on the screen when executed
CREATE OR REPLACE PROCEDURE greetings
AS
BEGIN
dbms_output.put_line('Hello World!');
END;
/
When above code is executed using SQL prompt, it will
produce the following result:
Procedure created.
PL/SQL program to call procedure
A standalone procedure can be called in two ways:
· Using the EXECUTE keyword
· Calling the name of the procedure from a PL/SQL block

88
RSCOEP COMPUTER ENGINEERING DEPARTMENT MRS.S.S.GHULE
The above procedure named 'greetings' can be called with
the EXECUTE keyword as:
EXECUTE greetings;
The procedure can also be called from another PL/SQL
block:
BEGIN
greetings;
END;
/
Syntax for drop procedure
DROP PROCEDURE procedure_name;
Example of drop procedure
BEGIN
DROP PROCEDURE greetings;
END;
/
3 Describe sequence in PL\SQL with example W-23 4
(Any relevant example should be considered)
A sequence is used to generate numbers in sequence. You can use
sequences to insert unique values in Primary Key and Unique Key
columns of tables. To create a sequence,
give the CREATE SEQUENCE statement.
Syntax for creating sequence:
CREATE SEQUENCE sequence_name
START WITH initial_value
INCREMENT BY increment_value
MINVALUE minimum value
MAXVALUE maximum value
CYCLE|NOCYCLE ;
.where as:sequence_name: Name of the sequence.
initial_value: starting value from where the sequence starts.
Initial_value should be greater than or equal to minimum value and
less than equal to maximum value.
increment_value: Value by which sequence will increment itself.
Increment_value can be positive or negative.
minimum_value: Minimum value of the sequence.
maximum_value: Maximum value of the sequence.
cycle: When sequence reaches its set_limit it starts from beginning.
nocycle: An exception will be thrown if sequence exceeds its
max_value.
Example
CREATE SEQUENCE sequence_1
start with 1
increment by 1
minvalue 0
maxvalue 100
cycle;
Alter sequence:
Syntax:
alter sequence <sequence_name> maxvalue <number>;

89
RSCOEP COMPUTER ENGINEERING DEPARTMENT MRS.S.S.GHULE
Alter sequence can change the maxvalue in the sequence created.
Example:
ALTER SEQUENCE employee_id_seq
INCREMENT BY 1
START WITH 10000
MINVALUE 1
MAXVALUE 99999
CACHE 10;
Dropping sequence:
Syntax:
drop sequence <sequence_name>;
To drop the sequence the DROP command is used.
Example:
DROP SEQUENCE employee_id_seq;
4 Compare database trigger and procedure(write four diierences and W-23 4
explain theuse of database trigger

5 Write a PL\SQL program to print sum of n odd numbers for using W-23 6
for loop
(Any other correct logic should be considered)
Declare
i number :=1;
sum number := 0;
n number;
begin
n := &n;
for i in 1..n
loop

if mod(i,2) = 1
then
sum := sum + i;
end if;
end loop;
dbms_output.put_line(‘sum= ’||sum);

90
RSCOEP COMPUTER ENGINEERING DEPARTMENT MRS.S.S.GHULE
end;
OR
Declare
i number :=1;
sum number := 0;
n number;
begin
n := &n;
for i in 1..n
loop
sum := sum + i;
i := i + 2;
end loop;
dbms_output.put_line(‘sum= ’||sum);
end;

1 Write PL/SQL code to print largest number from three numbers S-24 4
(accept 3 numbers from user)
declare
a number:=10;
b number:=12;
c number:=5;
begin
dbms_output.put_line('a='||a||' b='||b||' c='||c);
if a>b AND a>c
then
dbms_output.put_line('a is greatest');
else
if b>a AND b>c
then
dbms_output.put_line('b is greatest');
else
dbms_output.put_line('c is greatest');
end if;
end if;
end;
/
Output

a=10 b=12 c=5


b is greatest
2 Write pl\ sql program to print number of employee working in S-24 4
specifed department cnsider emp table and accept dept-no.for user

91
RSCOEP COMPUTER ENGINEERING DEPARTMENT MRS.S.S.GHULE
3 Write and explain syntax to create ,open and close cursor in S-24 4
PL/SQL

4 Difference between PL/SQL procedure and function with syntax S-24 6


and example

92
RSCOEP COMPUTER ENGINEERING DEPARTMENT MRS.S.S.GHULE
5 Explain use of database trigger .list types of trigger writ command S-24 6
to create and delete trigger

93
RSCOEP COMPUTER ENGINEERING DEPARTMENT MRS.S.S.GHULE
94
RSCOEP COMPUTER ENGINEERING DEPARTMENT MRS.S.S.GHULE
95
RSCOEP COMPUTER ENGINEERING DEPARTMENT MRS.S.S.GHULE
JSPM’s

RAJARSHI SHAHU COLLEGE OF ENGINEERING,


POLYTECHNIC
Department of Computer Engineering
Academic Year: 2024-25

UNIT-5 ( 10Marks)
MSBTE Question bank

Sr.No. Question Year Marks


1 Database security Database security refers to the collective measures W-18 4
used to protect and secure a database or database management
software from illegal use and malicious threats and
attacks.Requirements of Database Security:

1. For prevention of data theft such as bank account numbers, credit


card information, passwords, work related documents or sheets, etc.

2. 2. To make data remain safe and confidential.

3. To provide confidentiality which ensures that only those


individuals should ever entitled to. 4. To provide integrity which
ensures that only authorized individuals should ever be able change
or modify information.

5. To provide availability which ensure that the data or system itself


is available for use when authorized user wants it.

6. To provide authentication which deals with the desire to ensure


that an authorized individual.

7. To provide non-repudiation which deals with the ability to verify


that message has been sent and received by an authorized user.

OR

1. Confidentiality: The principle of confidentiality specifies that only


sender and intended recipients should be able to access the contents
of a message. Confidentiality gets compromised if an unauthorized
person is able to access the contents of a message

2. Integrity: when the contents of the message are changed after the
sender sends it, but before it reaches the intended recipient, we say
that the integrity of the message is lost.

3. Authentication:
96
RSCOEP COMPUTER ENGINEERING DEPARTMENT MRS.S.S.GHULE
Authentication helps to establish proof of identities. The

Database security Database security refers to the collective measures


used to protect and secure a database or database management
software from illegal use and malicious threats and
attacks.Requirements of Database Security:

4. For prevention of data theft such as bank account numbers, credit


card information, passwords, work related documents or sheets, etc.

5. 2. To make data remain safe and confidential.

6. To provide confidentiality which ensures that only those


individuals should ever entitled to. 4. To provide integrity which
ensures that only authorized individuals should ever be able change
or modify information.

8. To provide availability which ensure that the data or system itself


is available for use when authorized user wants it.

9. To provide authentication which deals with the desire to ensure


that an authorized individual.

10. To provide non-repudiation which deals with the ability to


verify that message has been sent and received by an authorized user.

OR

3. Confidentiality: The principle of confidentiality specifies that only


sender and intended recipients should be able to access the contents
of a message. Confidentiality gets compromised if an unauthorized
person is able to access the contents of a message

4. Integrity: when the contents of the message are changed after the
sender sends it, but before it reaches the intended recipient, we say
that the integrity of the message is lost. 3. Authentication:
Authentication helps to establish proof of identities. The

Authentication process ensures that the origin of a message is


correctly identified. 4. Availability: The goal of availability s to
ensure that the data, or the system itself, is available for use when the
authorized user wants it.

2 Explain transaction ACID properties. W-18 4

W-19

W-22

W-23

97
RSCOEP COMPUTER ENGINEERING DEPARTMENT MRS.S.S.GHULE
1. Atomicity: When one transaction takes place, many operations For each
occur under one transaction. Atomicity means either all operations
will take place property and reflect in the database or none of them property - 1
will be reflected. 2. Consistency: Consistency keeps the database Mark
consistent. Execution of a transactionneeds to take place in isolation. It
helps in reducing complications of executing multiple transactions at
a time and preserves the consistency of the database.3. Isolation: It is
necessary to maintain isolation for the transactions. This means one
transaction should not be aware of another transaction getting
executed. Also their intermediate result should be kept hidden. 4.
Durability: When a transaction gets completed successfully, it is
important that the changes made by the transaction should be
preserved in database in spite of system failures

3 Explain any four roles of database administrator W-18 4

1. Schema Definition The Database Administrator creates the


database schema by executing DDL statements. Schema includes the
logical structure of database table (Relation) like data types of
attributes, length of attributes, integrity constraints etc.

2. Storage structure and access method definition The DBA creates


appropriate

storage structures and access methods by writing a set of definitions


which is translated by data storage and DDL compiler.

3. Schema and physical organization modification DBA writes set of


definitions to modify the database schema or description of physical
storage organization

4. Granting authorization for data access The DBA provides different


access rights to the users according to their level. Ordinary users

98
RSCOEP COMPUTER ENGINEERING DEPARTMENT MRS.S.S.GHULE
might have highly restricted access to data, while you go up in the
hierarchy to the administrator, you will get more access

rights. Integrity constraints specifications: Integrity constraints are


written by DBA and they are stored in a special file which is accessed
by database manager while updating data.

5. Routine Maintenance some of the routine maintenance activities


of a DBA is given below.

(i) Taking backup of database periodically

(ii) Ensuring enough disk space is available all the time.

(iii) Monitoring jobs running on the database.

(iv) Ensure that performance is not degraded by some expensive task


submitted by some users.

6. Integrity- constraint specification: Integrity constraints are written


by DBA and they are stored in a special file, which is accessed by
database manager, while updating thedata.

1 Explain state of transaction with the help of diagram S-19 4

S-22

Active –the initial state; the transaction stays in this state while it is

executingPartially committed –after the final statement has been


executed.Failed - after the discovery that normal execution can no
longer proceed.Aborted – after the transaction has been rolled back
and the database restored to its state prior to the start of the
transaction. Two options after it has been aborted: restart the
transaction - can be done only if no internal logical error kill the
transaction Committed –after successful completion.

2 Explain recovery techniques with example. S-19 4

99
RSCOEP COMPUTER ENGINEERING DEPARTMENT MRS.S.S.GHULE
S-24

When recovering the database, it is must redo the effects of the


previous transactions. This is called Rolling Forward or simple
Forward Recovery. Not all but some active transaction that didn’t
complete successfully needs to rollback, when the disk drive crashed.
Such kind of rollback is called Backward Recovery.

The Redo Log and Rolling Forward (REDO operation)

The redo log is a set of operating system files that record all changes

made to any database buffer, including data, index, and rollback


segments, whether the changes are committed or uncommitted. The
redo log protects changes made to database buffers in memory that
have not been written to the data files.

The first step of recovery from an instance or disk failure is to roll


forward, or reapply all of the changes recorded in the redo log to the
data files. Because rollback data is also recorded in the redo log,
rolling forward also regenerates the corresponding rollback
segments.Rolling forward proceeds through as many redo log files
as necessary to bring the database forward in time. Rolling forward
usually includes online redo log files and may include archived redo
log files.After roll forward, the data blocks contain all committed
changes aswell as any uncommitted changes that were recorded in
the redo log.Rollback Segments and Rolling Back (UNDO
operation)Rollback segments record database actions that should be
undone during certain database operations. In database recovery,
rollback segments undo the effects of uncommitted transactions
previously applied by the rolling forward phase. After the roll
forward, any changes that were not committed must be undone. After
redo log files have reapplied all changes made to the database, then
the corresponding rollback segments are used. Rollback segments
are used to identify and undo transactions that were never committed,
yet were recorded in the redo log and applied to the database during
roll forward. This process is called rolling back.

100
RSCOEP COMPUTER ENGINEERING DEPARTMENT MRS.S.S.GHULE
1 Describe database backups with it’s types. W-19 4

Regular backups are required to protect database and ensure its


restoration in case of failure. Various backup types provide different
protection to our database. Backing up and restoring data is one of
the most important responsibilities of IT professionalsThree
common types of database backups can be run on a desired system:
normal (full), incremental and differential.

i) Normal or Full Backups:

When a normal or full backup runs on a selected drive, all the files
on that drive are backed up. This, of course, includes system files,
application files, user data — everything. Those files are then copied
to the selected destination (backup tapes, a secondary drive or the
cloud), and all the archive bits are then cleared.Normal backups are
the fastest source to restore lost data because all the data on a drive
is saved in one location.

ii) Incremental Backups:

A common way to deal with the long running times required for full
backups is to run them only on weekends. Many businesses then run
incremental backups throughout the week since they take far less
time. An incremental backup will grab only the files that have been
updated since the last normal backup. Once the incremental backup
has run, that file will not be backed up again unless it changes

or during the next full backup.

iii) Differential Backups:

101
RSCOEP COMPUTER ENGINEERING DEPARTMENT MRS.S.S.GHULE
An alternative to incremental database backups that has a less

complicated restore process is a differential backup. Differential

backups and recovery are similar to incremental in that these backups

grab only files that have been updated since the last normal backup.

However, differential backups do not clear the archive bit. So a file

that is updated after a normal backup will be archived every time a

differential backup is run until the next normal backup runs and
clears the archive bit

2 Describe database privileges. Write down the procedure for granting W-19 6
& revoking privileges in database objects to the users.

Database privileges: Procedu

When multiple users can access database objects, authorization can re for
be controlled to these objects with privileges. Every object has an
owner. Privileges control if a user can modify an object owned by granting
another user. Privileges are granted or revoked either by the instance privilege
administrator, a user with the ADMIN privilege or, for privileges to
a certain object, by the owner of the object. s

1) System Privileges: 2M

System privileges are privileges given to users to allow them to


perform certain functions that deal with managing the database and
the servere.gCreate user, Create table, Drop table etc.

2) Object Privileges:

Object privileges are privileges given to users as rights and


restrictions to change contents of database object – where database
objects are things like tables, stored procedures, indexes, etc.Ex.
Select,insert,delete,update,execute,references etcProcdure for
granting privileges

Grant: This command is used to give permission to user to do


operations on the other user’s object.

Syntax: Grant<object privileges>on<object

name>to<username>[with grant option] ;

102
RSCOEP COMPUTER ENGINEERING DEPARTMENT MRS.S.S.GHULE
Example: Grant select, update on emp to user1;Procedure for
revoking privileges

Revoke: This command is used to withdraw the privileges that


hasbeen granted to a user.

Syntax: Revoke <object privileges>on<object name>from

<username> ;

Example: Revoke select, update on emp from user1;

1 State the concept of database recovery. S-22 2

When recovering the database, it is must redo the effects of the


previous transactions. This is called Rolling Forward or simple
Forward Recovery. Not all but some active transaction that didn’t
complete successfully needs to rollback, when the disk drive crashed.
Such kind of rollback is called Backward Recovery

2 State types of database user S-22 2

1. Database Administrator (DBA)

2. Naive / Parametric End Users

3.Sophisticated Users

4.A System Analyst

2 Describe any four responsibilities of Database Administrator. W-22 4

Responsibilities of Database Administrator (DBA): Any 4: 1 M


each
1. Schema Definition:Database or schema can be designed or defined
by DBA.
2. Creating storage structure:
DBA allocate or decide the space to store the database.
3. Create grant access methods:
Different access methods to access the database can be granted by
DBA to the users.
4. Schema modification:

103
RSCOEP COMPUTER ENGINEERING DEPARTMENT MRS.S.S.GHULE
The database or schema which is already defined can be modified by
DBA as per the requirements.
5. Granting authorization:
To access the different databases, DBA can grant the authorization
to authorized users only.
6. Performance tuning:
The problems/errors arise in database accessing; can be resolved by
DBA to increase the performance.

7. Regular maintenance:
DBA can monitor the transactions in database and maintain the
database error free by doing the regular maintenance

3 Explain Database Recovery techniques in detail. W-22 4

Database Recovery Techniques:Database recovery techniques are


used to restore the original data in system from backup. Backward
and forward recovery is two types of database recovery.Recovery
Techniques:
1. Log based recovery.
2. Shadow paging recovery
3. Checkpoints

1. Log based recovery:


It records sequence of log records, which includes all activities done
by database users.It records the activities when user changes the
database.In case of database failure, by referring the log records users
can easily recover the data.

2. Shadow paging recovery:


This technique is the alternative for log based recovery.In this
technique, database is divided into pages that can be stored on the
disk.The page table is used to maintain the record of location of
pages.In case of database failure, page table is used to recover the
parts of database.

3. Checkpoints:
Checkpoint records all committed transactions into logs.When
system fails, it check log to determine recovery action.

1 Explain the most common types of database failures S-23 4

104
RSCOEP COMPUTER ENGINEERING DEPARTMENT MRS.S.S.GHULE
Define failure. Enlist types of failure W-23 2

Transaction Failures: Transactions can fail for a number of reasons. Any 2


Failure can be due to an error in the transaction caused by incorrect
input data as well as the detection of a present or potential deadlock. types of
Furthermore, some concurrency control algorithms do not permit a failure,
transaction to proceed or even to wait if the
2M each
data that they attempt to access are currently being accessed by
another transaction. This might also be considered a failure.

1. System Failures( or Hardware/ Software failure): The reasons for


system failure can be traced back to a hardware or to a software
failure.

2. Media Failures: Media failure refers to the failures of the


secondary storage devices that store the database. Such failures may
be due to operating system errors, as well as to hardware faults such
as head crashes or controller failures.

3. Communication/Network Failures: There are a number of types of


communication failures. The most common ones are the errors in
themessages, improperly ordered messages, lost messages, and
communication line failures mainly arising due to errors in network.

2 Explain properties of transaction S-23 4

A transaction can be defined as a group of tasks. A single task is the


minimum processing unit which cannot be divided further.

ACID Properties :A transaction is a very small unit of a program and


it may contain several low level tasks. A transaction in a database
system mustmaintain Atomicity, Consistency, Isolation, and
Durability −commonly known as

ACID properties − in order to ensure accuracy, completeness, and


data integrity.

on must be treated
as an atomic unit, that is, either all of its operations are executed or

105
RSCOEP COMPUTER ENGINEERING DEPARTMENT MRS.S.S.GHULE
none. There must be no state in a database where a transaction is left
partially completed. States should be defined either before the
execution of the transaction or after theexecution/abortion/failure of
the transaction.

n a consistent state after


any transaction. No transaction should have any adverse effect on the
data residing in the database. If the database was in a consistent state
before the execution of a transaction, it must remain consistent after
the execution of the transaction as well.

han one transactions


are being executed simultaneously and in parallel, the property of
isolation states that all the transactions will be carried out and
executed as if it is the only transaction

in the system. No transaction will affect the existence of any other


transaction.

ility: The database should be durable enough to hold all its


latest updates even if the system fails or restarts. If a transaction
updates a chunk of data in a database and commits, then the database
will hold the modified data. If a transaction commits but the system
fails before the data could be written on to the disk, then that data
will be updated once the system springs back into action

3 Describe database privileges. Write down the command for granting W-23 6
and revoking privileges on database object to users

A user privilege is the right to run a particular type of SQL statement,


or the right to access an object belonging to another user, run a
PL/SQL package, and so on.

There are two types of privileges defined by Oracle Database

1. System Privileges

2. Object Privileges

106
RSCOEP COMPUTER ENGINEERING DEPARTMENT MRS.S.S.GHULE
1. System Privileges

• There are over 100 distinct system privileges.

• Each system privilege allows a user to perform a particular database


operation. System privileges allow a user to perform administrative
actions in a database.

• System privileges can be very powerful, and should be granted only


when necessary to roles and trusted users of the database.

• For e.g.: create session, create table, create view, create sequence,
create procedure, create role

2. Object Privileges

• Each type of object (for e.g.: table, view, procedure etc.) has
different privileges associated with it.

• It allows for the use of certain operations on database objects as


authorized by another user

• All DML are comes under Object privileges.

• You can specify ALL [PRIVILEGES] to grant or revoke all


available object privileges for an object.

Grant Privileges

GRANT is used for giving privileges on various database objects in


OracleWe can grant users various privileges to tables.

These privileges can be any combination of SELECT, INSERT,


UPDATE, DELETE,

REFERENCES, ALTER, INDEX, or ALL.

Syntax

GRANT privilege-type ON [TABLE] {table-Name | view-Name}


TO grantees

Example:

grant create synonym to scott;

Revoke

Use the REVOKE statement to remove privileges from a specific


user or role, or from all users, to perform actions on database objects

107
RSCOEP COMPUTER ENGINEERING DEPARTMENT MRS.S.S.GHULE
Syntax:

REVOKE privilege-type ON [ TABLE] {table-Name | view-Name}


FROM grantees

revoke create synonym from scott;

1 List Privileges and object privileges S-24 2

There are two types of privileges defined by Oracle Database

1. System Privileges

2. Object Privileges

1. System Privileges

All DML are comes under Object privileges.

• You can specify ALL [PRIVILEGES] to grant or revoke all


available object

privileges for an object.Grant Privileges

GRANT is used for giving privileges on various database objects in


OracleWe can grant users various privileges to tables.

These privileges can be any combination of SELECT, INSERT,


UPDATE, DELETE,

REFERENCES, ALTER, INDEX, or ALL.

Syntax

GRANT privilege-type ON [TABLE] {table-Name | view-Name}


TO grantees

Example:

grant create synonym to scott;

Revoke

Use the REVOKE statement to remove privileges from a specific


user or role, or from all users, to perform actions on database objects

Syntax:

108
RSCOEP COMPUTER ENGINEERING DEPARTMENT MRS.S.S.GHULE
REVOKE privilege-type ON [ TABLE] {table-Name | view-Name}
FROM grantees

revoke create synonym from scott;

2 State the cause of database failure S-24 2

What Are The Causes of Database Loss? The database recovery


process is not entirely different from data recovery .....Power Failure.
Power failures can lead to hardware failure. ...

Disk Failure. ...

Human Error. ...

Software Corruption. ...

Virus Infection. ...

Natural Disasters. ...

Disgruntled Employees.
Jaywant Shikshan Prasarak Mandal’s
RAJARSHI SHAHU COLLEGE OF ENGINEERING’s
POLYTECHNIC
S.No.80, Pune-Mumbai Bypass Highway, Tathawade Campus, Pune.

Approved By AICTE & Govt. of Maharashtra, Affilated to MSBTE

NBA ACCREDITED

MSBTE QUESTION PAPAER


WINTER -2018

22319
11819
3 Hours / 70 Marks Seat No.
Instructions : (1) All questions are compulsory.
(2) Illustrate your answers with neat sketches wherever necessary.
(3) Figures to the right indicate full marks.
(4) Assume suitable data, if necessary.

Marks

1. Attempt any five of the following : 10


a) List disadvantages of typical file processing system.
b) Define i) data abstraction, ii) data redundancy.
c) Define the term :
i) Candidate key
ii) Primary key
d) List four DDL commands with syntax.
e) Define normalization, list its types.
f) Enlist four aggregate functions.
g) Define cursor. List the two types of cursor.

2. Attempt any three of the following : 12


a) Distinguish between network model and hierarchical model (any 4 points).
b) Explain set operators with example.
c) Explain any four string functions with example.
d) Describe exception handling in brief.

3. Attempt any three of the following : 12


a) Describe commit and rollback with syntax and example.
b) Explain joins in SQL with examples.
c) Explain function in PL/SQL with example.
d) Explain database security with it’s requirements in detail.

P.T.O.
22319
Marks
4. Attempt any three of the following : 12
a) Explain the four roles of database administrator.
b) State and explain 1NF and 2NF with example.
c) Draw the block structure of PL/SQL . List advantages of PL/SQL.
d) Write step by step syntax to create, open and close cursor in PL/SQL.
e) Explain transaction ACID properties.

5. Attempt any two of the following : 12


a) Draw an E-R diagram of library management system considering issue and return, fine
calculation facility, also show primary key, weak entity and strong entity.
b) Consider the following database Employee(emp_id, emp_name, emp_city, emp_addr,
emp_dept, join_date)
i) Display the emp_id, of employee who live in city ‘Pune’ or ‘Nagpur’.
ii) Change employee name, ‘Aayush’ to ‘Aayan’.
iii) Display the total number of employee whose dept is 50.
c) Consider the following schema Depositor (ACC_no, Name, PAN, Balance) Create a
view on Depositor having attributes (ACC_no, PAN) where balance is greater than 100000.

6. Attempt any two of the following : 12


a) Create a sequence
i) Sequence name is Seq_ 1, Start with 1, increment by 1, minimum value 1,
maximum value 20.
ii) Use a seq_1 to insert the values into table Student (ID Number (10), Name char (20));
iii) Change the seq_ 1 max value 20 to 50.
iv) Drop the sequence.
b) Write a PL/SQL program which accept the customer ID from the user if user enters an
invalid ID then the exception invalid_id is raised using exception handling.
c) i) Create user ‘Rahul’.
ii) Grant create, select, insert, update, delete, drop privilege to ‘Rahul’.
iii) Removes the select privilege from user ‘Rahul’.

––––––––––––––
SUMMER-2019 22319
21819
3 Hours / 70 Marks Seat No.

Instructions : (1) All Questions are compulsory.

(2) Illustrate your answers with neat sketches wherever necessary.

(3) Figures to the right indicate full marks.

(4) Assume suitable data, if necessary.

Marks
1. Attempt any FIVE of the following : 10
(a) Define :
(i) Instance (ii) Schema
(b) List any four advantages of DBMS.
(c) State any two E.F. Codd’s rule for RDBMS.
(d) List DCL commands.
(e) Define Normalization and list its types.
(f) Write syntax for creating synonyms with example.
(g) State any four PL/SQL datatypes.

2. Attempt any THREE of the following : 12


(a) Explain overall structure of DBMS with the help of diagram.
(b) Explain difference between delete and truncate command with example.
(c) Write and explain syntax for creating view with example.
(d) Explain PL/SQL block structure with the help of diagram.

[1 of 4] P.T.O.
22319 [2 of 4]
3. Attempt any THREE of the following : 12
(a) State and explain 2NF with example.
(b) Explain any four aggregate functions with example.
(c) Explain exception handling in PL/SQL with example.
(d) Explain state of transaction with the help of diagram.

4. Attempt any THREE of the following : 12


(a) State the difference between Relational and Hierarchical model.
(b) List the SQL operations and explain range searching operation ‘between’ and
pattern matching operator ‘like’ with example.
(c) Explain cursor with example.
(d) State the use of database trigger and also list types of trigger.
(e) Explain recovery techniques with example.

5. Attempt any TWO of the following : 12


(a) Draw ER diagram for library management system considering issue and
return, fine collection facility. Consider appropriate entities.
(b) Consider the table
Student (name, marks, dept, age, place, phone, birthdate) Write SQL query for
following :
(i) To list students having place as ‘Pune’ or ‘Jalgaon’.
(ii) To list students having same department (dept) as that of ‘Rachana’.
(iii) To change marks of ‘Rahul’ from 81 to 96.
(iv) To list student name and marks from ‘Computer’ dept.
(v) To list student name who have marks less than 40.
(vi) To list students who are not from ‘Mumbai’.
(c) Create simple and composite index. Write command to drop above index.
22319 [3 of 4]
6. Attempt any TWO of the following : 12

(a) (i) Write a command to create table student (RNo., name, marks, dept.)
with proper datatype and RNo as primary key.

(ii) Write a command to create and drop sequence.

(b) Write a PL/SQL program to calculate factorial of a given number.


(c) Write SQL command for following :

(i) Create user

(ii) Grant privileges to user

(iii) Remove privileges from user

P.T.O.
22319 [4 of 4]
WINTER-2019

22319
11920
3 Hours / 70 Marks Seat No.

Instructions : (1) All Questions are compulsory.


(2) Illustrate your answers with neat sketches wherever necessary.
(3) Figures to the right indicate full marks.
(4) Assume suitable data, if necessary.
(5) Mobile Phone, Pager and any other Electronic Communication
devices are not permissible in Examination Hall.

Marks

1. Attempt any FIVE of the following : 10


(a) State any two advantages of DBMS over file processing system.

(b) Draw three level architecture of DBMS.

(c) Define table and field.

(d) Enlist DML commands.

(e) Define primary key and foreign key.

(f) List any four string functions in SQL.

(g) State any two advantages of functions in PL/SQL.

2. Attempt any THREE of the following : 12


(a) Distinguish between Network and Hierarchical model. (Any four points)

(b) Explain any four set operators in SQL with example.

(c) Describe Views and write a command to create view.

(d) Explain implicit and explicit cursors.


[1 of 4] P.T.O.
22319 [2 of 4]
3. Attempt any THREE of the following : 12

(a) State and explain 3NF with example.

(b) Define index. Explain it’s types.

(c) Explain Exception handling with it’s types.

(d) Explain ACID properties of traction.

4. Attempt any THREE of the following : 12

(a) Explain strong and weak entity set.

(b) Describe create & alter command with syntax & example.

(c) Define database trigger. How to create and delete trigger ?

(d) Explain any one control structure in PL/SQL with example.

(e) Describe database backups with it’s types.

5. Attempt any TWO of the following : 12

(a) Draw an ER diagram for library management system. (Use Books, Publisher
& Member entities).

(b) Write a command to create table student (rollno, Stud_name, branch, class,
DOB, City, Contact_no) and write down queries for following :

(i) Insert one row into the table

(ii) Save the data

(iii) Insert second row into the table

(iv) Undo the insertion of second row

(v) Create save point S1.

(vi) Insert one row into the table.


22319 [3 of 4]
(c) Consider following schema :

EMP (empno, deptno, ename, salary, designation, join_date, DOB,


dept_location). Write down SQL queries for following :
(i) Display employees name & number in decreasing order of salary.
(ii) Display employee name & employee number whose designation is
Manager.
(iii) Display age of employees with ename.
(iv) Display total salary of all employees.
(v) Display employee names having deptno as 20 and dept_location is
Mumbai.
(vi) Display name of employee who earned lowest salary.

6. Attempt any TWO of the following : 12


(a) Consider the structure for book table as Book-Master (bookid, bookname,
author, no_of copies, price)
Write down SQL queries for following
(i) Write a command to create Book_master table.
(ii) Get authorwise list of all books.
(iii) Display all books whose price is between ` 500 & ` 800.
(iv) Display all books with details whose name start with ‘D’.
(v) Display all books whose price is above ` 700.
(vi) Display all books whose number of copies are less than 10.
(b) Write a PL/SQL program to print n even numbers using For Loop.
(c) Describe database privileges. Write down the procedure for granting &
revoking privileges in database objects to the users.

P.T.O.
22319 [4 of 4]
SUMMER-2022
22319
21222
3 Hours / 70 Marks Seat No.
15 minutes extra for each hour

Instructions – (1) All Questions are Compulsory.


(2) Answer each next main Question on a new page.
(3) Illustrate your answers with neat sketches
wherever necessary.
(4) Figures to the right indicate full marks.
(5) Assume suitable date, if necessary.
(6) Mobile Phone, Pager and any other Electronic
Communication devices are not permissible in
Examination Hall.

Marks

1. Attempt any FIVE of the following: 10


a) Define data model. List its types.
b) State the use of Avg function with example.
c) List two advantages of PL/SQL.
d) State the concept of database recovery.
e) State types of database user.
f) List any four data types in SQL.
g) State the components used in E-R diagram.

2. Attempt any THREE of the following: 12


a) Define Normalization. Explain 2NF with example.
b) Explain block structure of PL/SQL.
c) With neat sketch describe Transaction states diagram.
d) Explain any four string functions.
P.T.O.
22319 [2]
Marks
3. Attempt any THREE of the following: 12
a) With neat diagram explain three level architecture of database
system.
b) Explain conditional control in PL/SQL with example.
c) Explain any two DDL commands along with example.
d) Describe the concept of view with example. State its purpose.

4. Attempt any THREE of the following: 12


a) Explain advantages of DBMS over file processing system.
b) Write and explain syntax for creating Trigger.
c) Write syntax for
i) Create Index
ii) Drop Index
d) Explain.
i) Candidate key
ii) Foreign key

5. Attempt any TWO of the following: 12


a) Consider the schema Customer (Cust-id, Cust_name, Cust_addr,
Cust_city)
i) Create a view on Customer (Cust_id, Cust_name) where
Cust_city is ‘Pune’
ii) Create a sequence on Cust_id
b) Draw E-R diagram of Banking system considering deposite,
withdrawl facility. Also show primary key, weak entity,
strong entity.
c) i) Create table Student (S_id, S_name, S_addr, S_marks)
with proper data type and size.
ii) Insert row (5, ‘ABC’, ‘RRRRR’, 79) into student table.
iii) Update marks of student 85 where S_id is 5.
22319 [3]
Marks
6. Attempt any TWO of the following. 12
a) i) Create user ‘RAM’.
ii) Grant create, select, insert, update, delete privileges to user
‘RAM’.
iii) Remove update privilege from user ‘RAM’.
b) Write a PL/SQL program, which accept the number from user. If
user enters an odd number then exception invalid number is raised
using user defined exception handling.
c) Consider the following table employee (Emp_id, Emp_name,
Emp_age)
i) Display details of employees whose age is less than 30.
ii) Display details of employees whose age is in between
the range 30 to 60.
iii) Display total number of employee whose age is 60.
iv) Display names of employees whose name starts with 'S'.
v) Display details of employees whose name end with 'd'.
vi) Display details of employees whose age is greater than
50 and whose name contain 'e'.
WINTER -2022
SUMMER-2023

22319
22223
3 Hours / 70 Marks Seat No.

Instructions – (1) All Questions are Compulsory.


(2) Answer each next main Question on a new page.
(3) Illustrate your answers with neat sketches wherever
necessary.
(4) Figures to the right indicate full marks.
(5) Assume suitable data, if necessary.
(6) Mobile Phone, Pager and any other Electronic
Communication devices are not permissible in
Examination Hall.

Marks

1. Attempt any FIVE of the following: 10


a) Define the following terms:
i) Database
ii) DBMS
b) List any four codd's rules.
c) Explain subquery concept with example.
d) Define
i) Primary Key
ii) Candidate key
e) List any two DDL commands with syntax.
f) Draw the block structure of PL-SQL.
g) State syntax of while loop command.

P.T.O.
22319 [2]
Marks
2. Attempt any THREE of the following: 12
a) Explain not null and check constraint with example.
b) Explain any four string functions with example.
c) Describe Grant and Revoke commands with example.
d) Explain trigger with suitable example.

3. Attempt any THREE of the following: 12


a) Explain views with example.
b) Explain properties of transaction.
c) Write step by step syntax to create, open and close cursor
in PL/SQL
d) Explain savepoint and rollback command with example.

4. Attempt any THREE of the following: 12


a) Explain any four types of attributes with example.
b) Explain any four aggregate function with example.
c) Explain any four DML commands with syntax and example.
d) Write a PL-SQL program to print odd numbers from 1 to 10.
e) Explain the most common types of database failures.

5. Attempt any TWO of the following: 12


a) Explain strong and weak entity set with example. Draw
ER diagram indicating strong and weak entity set.
b) Explain for loop syntax in PL-SQL with example of printing
10 to 1 reverse numbers.
c) Explain function in PL-SQL with suitable example.
22319 [3]
Marks
6. Attempt any TWO of the following: 12
a) Draw an ER diagram of library management system considering
publisher, books, member. Also show primary key, weak entity
and strong entity.
b) State and explain 1 NF and 2 NF with example.
c) Explain any two types of join with example.
WINTER -2023 22319
23124
3 Hours / 70 Marks Seat No.

Instructions – (1) All Questions are Compulsory.


(2) Illustrate your answers with neat sketches wherever
necessary.
(3) Figures to the right indicate full marks.
(4) Assume suitable data, if necessary.
(5) Mobile Phone, Pager and any other Electronic
Communication devices are not permissible in
Examination Hall.

Marks

1. Attempt any FIVE of the following : 10


a) Enlist any two Applications of DBMS.
b) Define the following :
i) Instance
ii) Schema
c) List DML commands with its syntax. (Any Four)
d) List any four string functions in SQL.
e) Enlist types of SQL Joins.
f) Define cursor. Enlist the types of cursors.
g) Define failure. Enlist types of failure.

P.T.O.
22319 [2]
Marks
2. Attempt any THREE of the following : 12
a) State advantages of DBMS over file processing system.
(Any four)
b) Explain pattern matching operators ‘Like’ and range searching
operator ‘Between’ with example.
c) Explain any four aggregate functions with example.
d) Describe exception handling in PL/SQL.

3. Attempt any THREE of the following : 12


a) Explain commit and rollback with syntax and example.
b) Write and explain create, update and drop view commands.
c) Explain procedures in PL/SQL with example.
d) Describe ACID properties of transaction.

4. Attempt any THREE of the following : 12


a) Differentiate between network model and hierarchical model.
(Any four points)
b) Define Normalization. State and explain 2NF with example.
c) Explain cursor with syntax for declaring, opening and closing
a cursor.
d) Describe sequences in PL/SQL with example.
e) Compare database triggers and procedures. (Write four differences)
And explain the use of database trigger.
22319 [3]
Marks
5. Attempt any TWO of the following : 12
a) Draw ER diagram for Hospital management system.
(Use Entity-Doctor, Patient, Hospital and Medical Record).
Show Primary Key, and Foreign Key.
b) Write SQL query for the following consider table.
Emp(emp_id, dept, emp_name, salary, designation, joining_date,
DOB, city)
i) List employees with having alphabate ‘A’ as second letter
in their name.
ii) Set salary of all ‘project leaders’ to 50,000.
iii) Display average salary of all employees.
iv) Display employee-Id of employees who live in city
‘Pune’ or ‘Nagpur’.
v) Display employee name, salary and city from ‘HR’
department who having salary greater than 70,000.
vi) Display details of all employee who’s salary same as
that of salary of ‘Shashank’.
c) Consider schema of book table as Book_Master
(book_id, book_name, author, no_of_copies, price)
Write down the SQL queries for the following.
i) Write a query to create table Book_Master table.
ii) Write a command to create composite index on
Book_Master table.
iii) Write a command to drop above index.
iv) Display book name and author in decreasing order
of price.
v) Display all books whose number of copies are greater
than 50.
vi) Create synonym for relation Book_Master as
Book_Information.

P.T.O.
22319 [4]
Marks
6. Attempt any TWO of the following : 12
a) Write a PL/SQL program to print sum of n odd numbers
using for loop.
b) Write a command to create table Customer (Custo_id, Cust_name,
address, Contact_no, City). And write down the queries for the
following:
i) Insert one row into table.
ii) Save the data.
iii) Insert Second row into the table.
iv) Create save point S1.
v) Insert one row into the table.
c) Describe database privileges. Write down the command for
granting and revoking privileges on database object to users.
SUMMER-2024
JSPM’s
RAJARSHI SHAHU COLLEGE OF ENGINEERING,
POLYTECHNIC
Department of Computer Engineering
Academic Year: 2024-25

ALL THE BEST STUDENTS!

You might also like