DBMS Hunted
DBMS Hunted
----------------------------------------------------------------------------------------------------------------------------------------------
Pyq jun/jul – 1
1) Define database. Elaborate component modules of DBMS and their interactions.
2) Describe the three-schema architecture. Why do we need mappings among schema levels?
3) Explain the difference between logical and physical data independence.
4) Draw an ER diagram for a COMPANY database with employee, department, project as strong entities and
dependent as weak entity. Specify the constraints, relationships and ratios in the ER diagram.
5) Define the following terms with example for each using ER notations:
Entity, attribute, composite attribute, multivalued attribute, participation role.
----------------------------------------------------------------------------------------------------------------------------------------------
Pyq jun/jul – 2
6) What is DBMS? List the characteristics of database approach. Bring out major advantages of the
database approach.
7) Explain data independence. Draw 3 schema architecture and discuss the mapping.
8) Define the following: i) Database Administrator ii) Canned transaction
iii) Weak entity iv) Meta data v) Database Instance
9) Describe components modules of DBMS and its interaction with neat diagram.
10) Draw ER diagram of library database schema (at least 4 entities). Also specify primary keys, structural
constraints and explain.
11) Briefly discuss different types of end users of Database.
----------------------------------------------------------------------------------------------------------------------------------------------
Pyq dec/jan
12) Define the following terms: (i) Database (ii) Schema (iii) Entity
(iv) DDL (v) Degree of a relationship
13) Briefly explain characteristics of database approach.
14) List and explain advantages of using DBMS approach.
15) Define the following terms: (i) Cardinality (ii) Weak entity
(iii) Program data independence (iv) DML (v) Value sets
16) Describe three-schema architecture. Why do we need mappings between schema levels?
17) Explain different types of attributes in ER model with suitable example for each.
----------------------------------------------------------------------------------------------------------------------------------------------
Mqp- 1
18) Explain the types of end users with examples.
19) What are the advantages of using DBMS? Explain.
20) Describe the characteristics of database.
21) Explain three schema architecture. Why mappings b/w schema levels are required?
22) Explain the different types of attributes in ER model.
23) Explain the following. 1. Cardinality Ratio 2. Weal Entity
----------------------------------------------------------------------------------------------------------------------------------------------
Mqp- 2
24) What is a Database? Explain the three schema architecture with neat diagram.
25) What are the advantages of using DBMS approach? Explain
26) Explain the following terms. 1. Data Dictionary 2. Weak Entity
27) Explain the categories of Data Models.
28) Explain the component modules of DBMS & their interactions with diagram.
29) What are the responsibilities of DBA & database designers?
----------------------------------------------------------------------------------------------------------------------------------------------
Pyq jun/jul – 1
1) Define database. Elaborate component modules of DBMS and their interactions.
----------------------------------------------------------------------------------------------------------------------------------------------
* A database is a structured collection of related data that can be easily accessed, managed, and updated.
It is designed to store, retrieve, and manipulate data efficiently.
Example: A student database that stores details like roll number, name, marks, etc.
----------------------------------------------------------------------------------------------------------------------------------------------
These modules interact to process user queries, ensure data consistency, manage concurrent access, and
store the data efficiently .
2. Application Programs
Programs in Java/C include DML statements extracted by a precompiler and compiled into canned
transactions.
These transactions are repeatedly executed with user-supplied parameters for consistent operations.
4. Client-Server Architecture
Clients or middle-tier servers communicate with a remote DB server; OS or DBMS handles scheduling.
This allows multiple users to access and operate on shared or distributed databases efficiently.
advantages
Controlling Redundancy.
• In traditional file processing technique, every user group maintains its own files for handling its data-
processing applications, each group independently keeps files which leads to redundancy. Redundancy is
storing the same data multiple times in the database. A DBMS reduces data redundancy by integrating all
the data into a single database
Restricting Unauthorized Access
• When multiple users share a large database, it is likely that most users will not be authorized to access all
information in the database. For example, financial data is often considered confidential, and only
authorized persons are allowed to access such data.
Providing Persistent Storage for Program Objects.
• Databases can be used to provide persistent storage for program objects and data structures. This is one
of the main reasons for object-oriented database systems.
Providing Storage Structures and Search Techniques for Efficient Query Processing.
• The DBMS often has a buffering or caching module that maintains parts of the database in main memory
buffers. The query processing and optimization module of the DBMS is responsible for choosing an efficient
query execution plan for each query based on the existing storage structures.
Providing Backup and Recovery.
• The backup and recovery subsystem of the DBMS is responsible for recovery. In case of hardware or
computer system fails in the middle of a complex update transaction
Providing Multiple User Interfaces.
• Different types of users with varying levels of technical knowledge use a database, a DBMS provide a
variety of user interfaces.. Users can be granted different levels of access, ensuring data security and
integrity.
Representing Complex Relationships among Data.
• A database may include numerous varieties of data that are interrelated in many ways. • A DBMS have
the capability to represent a variety of complex relationships among the data.
Data Integrity:
• Constraints: Integrity constraints such as primary keys, foreign keys, and unique constraints help maintain
the accuracy and consistency of data.
Data Independence:
• Logical Data Independence: Changes to the logical schema do not affect the application programs.
• Physical Data Independence: Changes to the physical storage of data do not affect the logical schema or
application programs.
2) Explain data independence. What is a Database? Describe the three-schema architecture. Why do we
need mappings among schema levels? with neat diagram.
----------------------------------------------------------------------------------------------------------------------------------------------
A database is a structured collection of related data that can be easily accessed, managed, and updated. It
is designed to store, retrieve, and manipulate data efficiently.
Example: A student database that stores details like roll number, name, marks, etc
----------------------------------------------------------------------------------------------------------------------------------------------
Data Independence:
• Logical Data Independence: Changes to the logical schema do not affect the application programs.
• Physical Data Independence: Changes to the physical storage of data do not affect the logical schema or
application programs.
----------------------------------------------------------------------------------------------------------------------------------------------
The goal of the three-schema architecture is to separate the user applications from the physical database.
In this architecture, schemas can be defined at the following three levels:
* Ability to change the logical schema (e.g., adding/removing attributes, entities) without affecting
external views or application programs.
* Example: Adding a new column like Email to the Student table without modifying user queries using
Name or Roll_No.
----------------------------------------------------------------------------------------------------------------------------------------------
2. Physical Data Independence:
* Ability to change the physical storage (e.g., indexing method, file organization) without affecting the
logical schema.
* Example: Changing storage from heap files to B+ trees without changing the table definition or
application code.
----------------------------------------------------------------------------------------------------------------------------------------------
17) Explain different types of attributes in ER model with suitable example for each.
----------------------------------------------------------------------------------------------------------------------------------------------
1. Simple Attribute An attribute that cannot be further subdivided into components is a simple attribute.
Example: The roll number of a student, the ID number of an employee, gender, and many more.
----------------------------------------------------------------------------------------------------------------------------------------------
[Link] Attribute An attribute that can be split into multiple sub-attributes is a composite attribute.
Example: The address can be further split into house number, street number, city, state, country, and pin
code, the name can also be split into first name middle name, and last name.
----------------------------------------------------------------------------------------------------------------------------------------------
3. Single-Valued Attribute The attribute which takes up only a single value for each entity instance is a
single-valued attribute.
Example: The age of a student, Aadhar card number.
----------------------------------------------------------------------------------------------------------------------------------------------
4. Multi-Valued Attribute The attribute which takes up more than a single value for each entity instance is a
multi-valued attribute. And it is represented by double oval shape. Example: Phone number of a student:
Landline and mobile.
5. Stored Attribute The stored attribute are those attribute which doesn’t require any type of further
update since they are stored in the database.
Example: DOB(Date of birth) is the stored attribute.
----------------------------------------------------------------------------------------------------------------------------------------------
6. Derived Attribute An attribute that can be derived from other attributes is derived attributes. And it is
represented by dotted oval shape.
Example: Total and average marks of a student, age of an employee that is derived from date of birth.
----------------------------------------------------------------------------------------------------------------------------------------------
7. Complex Attribute Those attributes, which can be formed by the nesting of composite and multi valued
attributes, are called “Complex Attributes“. These attributes are rarely used in DBMS(DataBase
Management System). That’s why they are not so popular.
Example: Address because address contain composite value like street, city, state, PIN code and also
multivalued because one people has more that one house address.
----------------------------------------------------------------------------------------------------------------------------------------------
8. Key attribute Key attributes are those attributes that can uniquely identify the entity in the entity set.
Example: Roll-No is the key attribute because it can uniquely identify the student.
----------------------------------------------------------------------------------------------------------------------------------------------
18) Explain the types of end users with examples.
----------------------------------------------------------------------------------------------------------------------------------------------
1. Casual End Users
• occasionally access the database, but they may need different information each time. They use a
sophisticated database query language to specify their requests and are typically middle- or high-level
managers or other occasional browsers.
• Example: A manager who occasionally queries the database to generate a sales report.
----------------------------------------------------------------------------------------------------------------------------------------------
2. Naive or Parametric End Users
• These users frequently use the database but have a limited understanding of its complexities. They often
interact with the system through pre-defined functions or transactions.
• Example:
1. Bank tellers check account balances and post withdrawals and deposits.
2. Reservation agents for airlines, hotels, and car rental companies check availability for a given request and
make reservations.
----------------------------------------------------------------------------------------------------------------------------------------------
3. Sophisticated End Users
• include engineers, scientists, business analysts, and others who thoroughly familiarize themselves with
the facilities of the DBMS in order to implement their own applications to meet their complex
requirements.
• Example: A data analyst who writes SQL queries to extract, manipulate, and analyze large datasets for
business insights.
----------------------------------------------------------------------------------------------------------------------------------------------
4. Stand-alone Users
• These users maintain personal databases by using ready-made program packages that provide easy-to-
use menu-based or graphics-based interfaces.
• Example: A small business owner who uses Microsoft Access to manage customer information and sales
records.
----------------------------------------------------------------------------------------------------------------------------------------------
5) Define the following terms with example for each using ER notations:
Entity, attribute, composite attribute, multivalued attribute, participation role.
----------------------------------------------------------------------------------------------------------------------------------------------
Entity: An entity is a real-world object or thing represented in a database, depicted as a rectangle in ER
notation.
* Example: A "Student" entity, shown as a rectangle labeled "Student."
----------------------------------------------------------------------------------------------------------------------------------------------
Attribute: An attribute is a property or characteristic of an entity, represented as an oval connected to the
entity rectangle.
* Example: The "StudentID" attribute of the "Student" entity, shown as an oval labeled "StudentID" linked
to the "Student" rectangle.
----------------------------------------------------------------------------------------------------------------------------------------------
Composite Attribute: A composite attribute is an attribute made up of multiple sub-attributes, shown as
ovals connected to a parent oval.
* Example: The "Address" attribute of "Student" with sub-attributes "Street," "City," and "Zip," where
"Address" is an oval with connected ovals for its components.
----------------------------------------------------------------------------------------------------------------------------------------------
multivalued attribute: The attribute which takes up more than a single value for each entity instance is a
multi-valued attribute. And it is represented by double oval shape.
* Example: Phone number of a student: Landline and mobile.
----------------------------------------------------------------------------------------------------------------------------------------------
participation role:A participation role defines the function of an entity in a relationship, labeled on the line
connecting entities to a diamond-shaped relationship.
Example: In a relationship "Enrolls" between "Student" and "Course," the role "Enrollee" for "Student" is
labeled on the line from "Student" to the "Enrolls" diamond.
E1= Student ,R= Enrolls ,E2= Course
8) Define the following: 1) Database Administrator 2) Canned transaction
3) Weak entity 4) Meta data 5) Database Instance
6) Database 7) Schema 8) Entity
9) DDL 10) Degree of a relationship 11) Cardinality
12) Program data independence 13) DML 14) Value sets
15) Cardinality Ratio 16) Data Dictionary
----------------------------------------------------------------------------------------------------------------------------------------------
Database Administrator:
A database administrator (DBA) is a person responsible for managing and maintaining a database system,
ensuring its performance, security, and integrity. They handle tasks like user access control, backup,
recovery, and schema design. The DBA keep the database running smoothly.
----------------------------------------------------------------------------------------------------------------------------------------------
Canned Transaction:
A canned transaction is a pre-defined, standardized set of database operations executed as a single unit,
often used for routine tasks. For example, a bank withdrawal process that deducts money and updates the
account balance is a canned transaction
----------------------------------------------------------------------------------------------------------------------------------------------
weak entity
weak entity is an entity that cannot be uniquely identified by its own attributes alone. It relies on a
"strong" or "owner" entity and a relationship with that entity to ensure its uniqueness. It is represented with
a double rectangle in ER diagrams.
----------------------------------------------------------------------------------------------------------------------------------------------
Meta Data: Meta data is data about data, describing the structure, properties, and context of the database,
such as table names or data types. For example, a catalog storing information about a "Student" table’s
columns is meta data.
----------------------------------------------------------------------------------------------------------------------------------------------
Database Instance:
A database instance is the current state or snapshot of the database at a specific time, containing the
actual data stored. For example, a "Student" table with 50 records at 08:14 PM on July 05, 2025, is an
instance. It changes with data updates or transactions.
----------------------------------------------------------------------------------------------------------------------------------------------
database
A database is a structured collection of related data that can be easily accessed, managed, and updated. It
is designed to store, retrieve, and manipulate data efficiently.
Example: A student database that stores details like roll number, name, marks, etc.
----------------------------------------------------------------------------------------------------------------------------------------------
Schema
A schema is the logical structure or blueprint of a database, defining how data is organized, such as tables
and their relationships.
----------------------------------------------------------------------------------------------------------------------------------------------
Entity:
An entity is a real-world object or thing represented in a database, depicted as a rectangle in ER notation.
* Example: A "Student" entity, shown as a rectangle labeled "Student."
----------------------------------------------------------------------------------------------------------------------------------------------
DDL:
Data Definition Language (DDL) is a set of SQL commands used to define and modify the database
structure, like creating, droping or altering tables. For example, "CREATE TABLE Student (StudentID INT)" is
a DDL command. It helps design the schema.
----------------------------------------------------------------------------------------------------------------------------------------------
Degree of a Relationship:
The degree of a relationship is the number of entity types involved in a relationship, e.g., unary (one entity)
or binary (two entities). For instance, a "Manages" relationship between "Employee" and "Employee" is
unary with a degree of 1
----------------------------------------------------------------------------------------------------------------------------------------------
Cardinality: Cardinality indicates the number of instances of one entity that can be associated with each
instance of another entity in a relationship. For example, a "Student" can enroll in many "Courses,"
indicating a one-to-many cardinality
----------------------------------------------------------------------------------------------------------------------------------------------
Cardinality Ratio: Cardinality ratio specifies the maximum number of relationship instances an entity can
participate in, like 1:1 or 1:N.
----------------------------------------------------------------------------------------------------------------------------------------------
Program Data Independence: Program data independence allows application programs to remain
unaffected by changes in the database structure or storage details.
1. Logical Data Independence:
* Ability to change the logical schema (e.g., adding/removing attributes, entities) without affecting external
views or application programs.
2. Physical Data Independence:
* Ability to change the physical storage (e.g., indexing method, file organization) without affecting the
logical schema.
----------------------------------------------------------------------------------------------------------------------------------------------
DML: Data Manipulation Language (DML) is a set of SQL commands used to manipulate data, such as
inserting, updating, or deleting records. For example, "INSERT INTO Student VALUES (1, 'John')" is a DML
command
----------------------------------------------------------------------------------------------------------------------------------------------
Value sets
Each simple attribute of an entity is associates with a domain of values, or value set, which specifies the set
of values that may be assigned to that attribute for each entity.
For example, the "Grade" attribute of a "Student" might have a value set of {A, B, C, D, F}. It ensures data
validity.
----------------------------------------------------------------------------------------------------------------------------------------------
Data Dictionary: A data dictionary is a repository that stores meta data about the database, including table
definitions and constraints. For example, it might list all attributes of the "Student" table. It aids in database
management and access.
----------------------------------------------------------------------------------------------------------------------------------------------
27) Explain the categories of Data Models.
----------------------------------------------------------------------------------------------------------------------------------------------
High-level or conceptual data models provide concepts that are close to the way many users
perceive data, Conceptual data models use concepts such as entities, attributes, and relationships.
An entity represents a real-world object or concept, such as an employee or a project from the miniworld
that is described in the database.
An attribute represents some property of interest that further describes an entity, such as the employee’s
name or salary.
A relationship among two or more entities represents an association among the entities, for example, a
works-on relationship between an employee and a project.
----------------------------------------------------------------------------------------------------------------------------------------------
• Representational or implementation data models are used most frequently in traditional commercial
DBMSs. These include the widely used relational data model, as well as the so-called
legacy data models—the network and hierarchical models— Representational data models
represent data by using record structures and hence are sometimes called record-based data models.
----------------------------------------------------------------------------------------------------------------------------------------------
• low-level or physical data models describe how data is stored as files in the computer by representing
information such as record formats, record orderings, and access paths. An access path is a structure that
makes the search for particular database records efficient. An index is an example of an access path that
allows direct access to data using an index term or a keyword. Concepts provided by low-level data models
are generally meant for computer specialists, not for end users.
----------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------
5) Consider the following relational database schema and write the queries in relational algebra
expressions:
(i) Find the names and salaries of all employees in the ‘IT’ department.
(ii) Find the ID’s and names of employees who are in the ‘IT’ department and have a salary greater than
6000.
(iii) Find the ID’s and names of employees who are either in the ‘HR’ department or have a salary greater
than 6000.
(iv) Find the names of employees who are not in the ‘IT’ department.
(v) Find the names of employees along with their department names.
---
14) Explain any two operations that change the state of relation in a database. Provide suitable examples.
15) Discuss the aggregation functions and grouping in relational algebra with suitable examples.
16) Given the relational tables:
21) Discuss the Equijoin & Natural Join with suitable example.
22) Explain the relational algebra operation for set theory with examples.
----------------------------------------------------------------------------------------------------------------------------------------------
Mqp – 2
23) Explain the different types of update operations on relational database. How basic operation deals with
constraint violation.
24) Explain Unary relational operations with examples.
25) What is an Integrity Constraint? Explain the importance of Referential Integrity Constraint.
26) Explain the following relational algebra operation. JOIN, DIFFERENCE, SELECT, UNION
27) Discuss the E.R to Relational mapping algorithm with example for each step.
28) Explain the relational algebra operation for set theory with examples.
----------------------------------------------------------------------------------------------------------------------------------------------
1) Discuss the update operations and dealing with constraint violations with suitable examples
----------------------------------------------------------------------------------------------------------------------------------------------
Update operation includes:
1) Insert
2) Update
3) delete
----------------------------------------------------------------------------------------------------------------------------------------------
1) insert
* The Insert operation provides a list of attribute values for a new tuple t that is to be inserted into a
relation R.
* Insert can violate any of the four types of constraints.
a) Domain constraints Occurs when the inserted value does not match the specified data type or domain
range.
Ex: CREATE TABLE Student (StudentID INT PRIMARY KEY, Name VARCHAR(50) NOT NULL, Age INT CHECK
(Age BETWEEN 18 AND 30));
INSERT INTO Student (StudentID, Name, Age) VALUES (101, 'John Doe', 15);
b) Key constraints Occurs when inserting a duplicate primary key or a non-unique value in a unique key
column.
Ex: INSERT INTO Student (StudentID, Name, Age) VALUES (101, 'Alice', 22);
INSERT INTO Student (StudentID, Name, Age) VALUES (101, 'Bob', 25);
c) Entity Integrity Occurs when a NULL value is inserted into a PRIMARY KEY column.
Ex: INSERT INTO Student (StudentID, Name, Age) VALUES (NULL, 'Charlie', 24);
d) Referential Integrity Occurs when an inserted foreign key value does not exist in the referenced table.
Ex: CREATE TABLE Course (CourseID INT PRIMARY KEY, CourseName VARCHAR(50));
CREATE TABLE Enrollment (StudentID INT, CourseID INT, FOREIGN KEY (CourseID) REFERENCES
Course(CourseID));
INSERT INTO Enrollment (StudentID, CourseID) VALUES (101, 500);
* attempts to add a record where CourseID = 500 does not exist in the Course table.
----------------------------------------------------------------------------------------------------------------------------------------------
2) UPDATE:
The Update operation is used to change the values of one or more attributes in a tuple (or tuples) of some
relation R.
a) Domain constraints Occurs when an updated value does not match the data type or domain range.
Ex: CREATE TABLE Student (StudentID INT PRIMARY KEY, Name VARCHAR(50) NOT NULL, Age INT CHECK
(Age BETWEEN 18 AND 30));
INSERT INTO Student (StudentID, Name, Age) VALUES (101, 'Alice', 22);
UPDATE Student SET Age = 10 WHERE StudentID = 101;
d) Referential Integrity Occurs when updating a referenced foreign key to a non-existing value.
Ex: UPDATE Enrollment SET CourseID = 999 WHERE StudentID = 101;
* attempts to update a record where CourseID = 999 does not exist in the Course table.
----------------------------------------------------------------------------------------------------------------------------------------------
3) DELETE:
Delete is used to delete tuples. A DELETE operation can cause only referential integrity violations.
a) Referential Integrity Violation Occurs when attempting to delete a row that is referenced by a foreign
key.
Ex: DELETE FROM Course WHERE CourseID = 101;
* here KEY (CourseID) REFERENCES Course(CourseID))
----------------------------------------------------------------------------------------------------------------------------------------------
2) Illustrate the relational algebra operators with examples for select and project operation.
----------------------------------------------------------------------------------------------------------------------------------------------
The SELECT Operation.
* The SELECT operation is used to choose a subset of the tuples from a relation that satisfies a selection
condition.
* The SELECT operation is visualized as a horizontal partition of the relation into two sets of tuples. Those
tuples that satisfy the condition are selected, and those
tuples that do not satisfy the condition are discarded.
* In general, the SELECT operation is denoted by σ <selection condition>(R)where the symbol σ (sigma) is
used to denote the SELECT operator and the selection condition is a Boolean expression (condition)
specified on the attributes of relation R.
Example 1: To select the EMPLOYEE tuples whose department is4, or those whose salary is greater than
$30,000, we can individually specify each of these two conditions with a SELECT operation as follows:
σDno=4(EMPLOYEE)
σSalary>3000(EMPLOYEE)
* The Boolean expression specified in <selection condition> is made up of a number of clauses of the form
<attribute name><comparison op><constant value>
or
<attribute name><comparison op><attribute name>
----------------------------------------------------------------------------------------------------------------------------------------------
The PROJECT Operation
* The SELECT operation chooses some of the rowsfrom the table while discarding other rows. The PROJECT
operation, on the otherhand, selects certain columns from the table and discards the other columns.
Example : To list each employee’s first and last name and salary, we can use the PROJECT operation as
follows:
πLname, Fname, Salary(EMPLOYEE)
* The general form of the PROJECT operation is π<attribute list>(R) where π (pi) is the symbol used to
represent the PROJECT operation, and <attributelist> is the desired sub list of attributes from the attributes
of relation R
* The PROJECT operation removes any duplicate tuples, so the result of the PROJECT operation is a set of
distinct tuples, and hence a valid relation. This is known as duplicate elimination.
----------------------------------------------------------------------------------------------------------------------------------------------
3) Discuss the characteristics of relations that make them different from ordinary table and files.
----------------------------------------------------------------------------------------------------------------------------------------------
1. Tabular Structure (Relations are Tables)
● A relation is represented as a table of rows and columns. Each row represents a tuple (or record), and
each column represents an attribute (orfield).
● Tuples in a relation are ordered conceptually but not physically, meaning the order of rows does not
affect the relation.
----------------------------------------------------------------------------------------------------------------------------------------------
2. Uniqueness of Tuples
● In a relational model, each tuple must be unique. No two rows can have identical values for all attributes.
This is enforced by the primary key, aunique identifier for each tuple.
----------------------------------------------------------------------------------------------------------------------------------------------
3. Attributes and Domains
● Each column (attribute) in a relation is associated with a domain, which defines the permissible values
the attribute can take. For example, a domain for a "Date of Birth" column might only accept valid date
values.
● Attributes must maintain atomicity
----------------------------------------------------------------------------------------------------------------------------------------------
4. No Duplicates
● Relations do not allow duplicate tuples. Each tuple must be distinct, as a relation is a set of tuples and
sets do not contain duplicate elements.
----------------------------------------------------------------------------------------------------------------------------------------------
5. Unordered Tuples and Attributes
● Tuples (rows) in a relation are not ordered. Unlike arrays or lists in programming, the order of tuples is
irrelevant, and the DBMS does not enforce a particular order.
● Attributes (columns) are also unordered, meaning the left-to-right order of columns does not affect the
definition or behavior of the relation.
----------------------------------------------------------------------------------------------------------------------------------------------
6. Integrity Constraints
● Relations are subject to various integrity constraints that ensure the correctness and consistency of the
data: example of constraints are ○ Domain constraints: ○ Key constraints:
--------------------------------------------------------------------------------------------------------------------------------------------
○ Referential integrity: ○ Entity integrity:
7. Relational Operations
● Relations support specific operations defined by relational algebra,including:
○ Selection: ○ Projection: ○ Join: ○ Union, Intersection, and Difference:
----------------------------------------------------------------------------------------------------------------------------------------------
8. Data Independence
● Relations are abstract representations of data, which provides data independence. Changes to the
physical storage of data do not affect the logical structure of relations, meaning users interact with data at a
higher level of abstraction.
----------------------------------------------------------------------------------------------------------------------------------------------
9. Set-Based Theory
10. Null Values
11. Normalization
----------------------------------------------------------------------------------------------------------------------------------------------
4) Perform
(i) Student ∪ Instructor (ii) Student ∩ Instructor
(iii) Student – Instructor (iv) Instructor − Student
on the following tables:
5) Consider the following relational database schema and write the queries in relational algebra
expressions:
i) π_PName(σ_Colour='red'(Parts))
ii) π_Price(σ_Colour='red'∨Colour='green'(Catalog ⨝ Parts))
or
π_Price((σ_Colour='red'∨Colour='green' (parts)) ⨝
[Link]=[Link] Catalog )
iii) π_SID(σ_Colour='red'∨Colour='green'(Catalog ⨝ Parts))
or
π_SID((σ_Colour='red'∨Colour='green' (parts)) ⨝
[Link]=[Link] Catalog )
iv) Reds := π_SID(σ_Colour='red'(Catalog ⨝ Parts))
Greens := π_SID(σ_Colour='green'(Catalog ⨝ Parts))
Answer := Reds ∩ Greens
Relation S
(B):
(x),
(y)
Cartesian Product (R ×\times× S): Pairs every A with every B. Result:
A B
1 x
1 y
2 x
2 y
11) With suitable example, explain the entity integrity and referential integrity constraints. Why each is
considered important?
----------------------------------------------------------------------------------------------------------------------------------------------
(cascade delete) or that the foreign key should be set to null (set null) when a
customer record is deleted.
12) Discuss equijoin and natural join with suitable example using relational algebra notation.
1. Equijoin
An equijoin combines tuples from two relations where the values of specified attributes are equal, using
the ⋈ (theta join) operator with an equality condition. It retains all columns from both relations, including
the join attributes, which may appear multiple times.
Example:
Relation R (A, B):
A B
1 x
2 y
14) Explain any two operations that change the state of relation in a database. Provide suitable examples.
----------------------------------------------------------------------------------------------------------------------------------------------
In a relational database, operations that change the state of a relation (i.e., modify the data or structure of
a table) are typically part of the Data Manipulation Language (DML)
That are insert , update , delete ( WRITE ANY TWO )
----------------------------------------------------------------------------------------------------------------------------------------------
1. INSERT Operation The INSERT operation adds new rows (tuples) to a relation, thereby changing its
state by increasing the number of records.
Example: Before INSERT into Employee table:
EID Name DeptID Salary
1 Alice 10 5000
2 Bob 20 6000
SQL Operation:
INSERT INTO Employee VALUES (3, 'Eve', 20, 6500);
EID Name DeptID Salary
1 Alice 10 5000
2 Bob 20 6000
3 Eve 20 6500
----------------------------------------------------------------------------------------------------------------------------------------------
2. DELETE Operation
Purpose: Removes one or more tuples from a relation.
Effect on Relation State: Decreases the number of rows → removes data.
Example:
Before:
EID Name DeptID Salary
1 Alice 10 5000
2 Bob 20 6000
SQL:
DELETE FROM Employee WHERE EID = 1;
After:
EID Name DeptID Salary
2 Bob 20 6000
----------------------------------------------------------------------------------------------------------------------------------------------
3. UPDATE Operation
Purpose: Modifies the values of existing attributes in one or more tuples.
Effect on Relation State: Changes data values without adding or removing rows.
Example:
Before:
EID Name DeptID Salary
2 Bob 20 6000
SQL:
UPDATE Employee SET Salary = 7000 WHERE Name = 'Bob';
After:
EID Name DeptID Salary
2 Bob 20 7000
15) Discuss the aggregation functions and grouping in relational algebra with suitable examples.
----------------------------------------------------------------------------------------------------------------------------------------------
1. Aggregation Functions
Aggregation functions are used in relational algebra to perform calculations on sets of values in a column
(attribute). They return a single value from multiple tuples.
----------------------------------------------------------------------------------------------------------------------------------------------
Common Aggregation Functions:
Function Meaning
COUNT Counts the number of tuples
SUM Computes the total sum
AVG Computes the average
MAX Finds the maximum value
MIN Finds the minimum value
----------------------------------------------------------------------------------------------------------------------------------------------
Syntax (Extended Relational Algebra):
𝛾 grouping_attributes; aggregations (Relation)
----------------------------------------------------------------------------------------------------------------------------------------------
2. Grouping with Aggregation
Grouping is used when you want to apply an aggregation function within groups of tuples that share a
common value in one or more attributes.
----------------------------------------------------------------------------------------------------------------------------------------------
Example Schema:
Employee(EID, Name, DeptID, Salary)
EID Name DeptID Salary
1 Alice 10 5000
2 Bob 20 6000
3 Eve 20 6500
4 John 10 5500
----------------------------------------------------------------------------------------------------------------------------------------------
Example 1: Find total salary of all employees.
𝛾 SUM(Salary) (Employee)
Result:
SUM(Salary)
23000
----------------------------------------------------------------------------------------------------------------------------------------------
Example 2: Count number of employees in each department.
𝛾 DeptID; COUNT(EID) (Employee)
Result:
DeptID COUNT(EID)
10 2
20 2
----------------------------------------------------------------------------------------------------------------------------------------------
Example 3: Find average salary per department.
𝛾 DeptID; AVG(Salary) (Employee)
Result:
DeptID AVG(Salary)
10 5250
20 6250
16) Given the relational tables:
Write relational algebra expression for the following:
Now both Car and Bike become subsets of the Vehicle entity.
----------------------------------------------------------------------------------------------------------------------------------------------
ER Diagram Sketch
Vehicle
/ \
Car Bike
----------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------
2. Specialization
* Specialization is the process of dividing a higher-level entity into two or more lower-level entities based
on distinguishing characteristics.
* It’s a top-down approach.
* Helps when a superclass has multiple distinct roles or behaviors that require specific attributes or
relationships.
----------------------------------------------------------------------------------------------------------------------------------------------
Example:
Higher-level entity:
• Employee(EID, Name, Salary)
Specialized into:
• Manager(EID, Bonus)
• Developer(EID, ProgrammingLanguage)
Now, Manager and Developer inherit from Employee but have additional attributes.
----------------------------------------------------------------------------------------------------------------------------------------------
ER Diagram Sketch
Employee
/ \
Manager Developer
22) Explain the relational algebra operation for set theory with examples.
----------------------------------------------------------------------------------------------------------------------------------------------
1. Union (∪)
Combines tuples from two relations, removing duplicates, provided they have the same schema
(compatible attributes).
Example:
o Relation R (A, B):
AB
1x
2y
o Relation S (A, B):
AB
2y
3z
o Expression: R∪S
o Result:
AB
1x
2y
3z
Explanation: Combines all unique tuples from R and S, removing the duplicate (2, y).
----------------------------------------------------------------------------------------------------------------------------------------------
2. Intersection (∩)
Returns tuples that appear in both relations, requiring compatible schemas.
Example:
o Relation R (A, B) (same as above):
AB
1x
2y
o Relation S (A, B) (same as above):
AB
2y
3z
o Expression: R∩S
o Result:
AB
2y
Explanation: Includes only the tuple (2, y) common to both R and S.
----------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------
3. Difference (−−)
Returns tuples that are in the first relation but not in the second, requiring compatible schemas.
Example:
o Relation R (A, B) (same as above):
AB
1x
2y
o Relation S (A, B) (same as above):
AB
2y
3z
o Expression: R−S
o Result:
AB
1x
Explanation: Includes only (1, x) from R that is not in S.
----------------------------------------------------------------------------------------------------------------------------------------------
4. Cartesian Product (×)
Combines every tuple of the first relation with every tuple of the second, creating all possible pairs. The
resulting relation has attributes from both relations.
Example:
o Relation R (A):
A
1
2
o Relation S (B):
B
x
y
o Expression: R×S
o Result:
AB
1x
1y
2x
2y
Explanation: Pairs each A value with each B value, resulting in 4 tuples.
----------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------
5. Rename (ρ)
Renames a relation or its attributes without changing the data, useful for clarity or reuse in expressions.
Syntax:
ρ NewRelationName (OldRelation)
or
ρ NewRelationName (A1,A2) (OldRelation )
Example:
If
Student(SID, Name)
Then
ρLearner(LID,LName)(Student)
→ Renames relation and attributes.
----------------------------------------------------------------------------------------------------------------------------------------------
26) Explain the following relational algebra operation. JOIN, DIFFERENCE, SELECT, UNION
----------------------------------------------------------------------------------------------------------------------------------------------
1. JOIN
The JOIN operation combines tuples from two relations based on a common attribute, creating a new
relation with matched rows. Common types include natural join (⋈\bowtie⋈) and theta join
(⋈θ\bowtie_{\theta}⋈θ).
Example:
o Relation R (A, B):
AB
1x
2y
o Relation S (B, C):
BC
x 10
y 20
z 30
----------------------------------------------------------------------------------------------------------------------------------------------
3. SELECT (σ\sigmaσ)
The SELECT operation filters tuples from a single relation based on a condition, retaining rows that satisfy it.
Example:
o Relation R (A, B):
AB
1x
2y
3z
4. UNION (∪\cup∪)
The UNION operation combines tuples from two relations, removing duplicates, provided they have the
same schema.
Example:
o Relation R (A, B):
AB
1x
2y
o Relation S (A, B):
AB
2y
3z
Mqp –1
20) Explain the Cursor & its properties in embedded SQL with an example.
21) What is a Normalization? Explain the 1NF, 2NF & 3NF with examples.
22) Explain informal design guidelines for relational schema design.
23) What is Functional Dependency? Write algorithm to find minimal cover for set of Functional
Dependency. Construct the minimal cover m for set of functional dependency.
E = { B → A, D → A, AB → D }
25) Explain the types of update anomalies in SQL with an example.
----------------------------------------------------------------------------------------------------------------------------------------------
Mqp – 2
26) Illustrate insert, delete, update, alter & drop commands in SQL.
27) Explain informal design guidelines for relational schema design.
28) What is Functional dependency? Explain the inference rules for functional dependency with proof.
29) Consider two sets of functional dependency.
F = {A → C, AC → D, E → AD, E → H}
E = {A → CD, E → AH}. Are they Equivalent? (yes )
30) Explain the types of update anomalies in SQL with an example.
----------------------------------------------------------------------------------------------------------------------------------------------
1) Discuss the informal design guidelines for relation schema design.
* There are four informal guidelines that may be used as measures to determine the quality of relation
Schema design:
1) Making sure that the semantics of the attributes is clear in the Schema.
2) Reducing the redundant information in tuples.
3) Reducing the NULL values in tuples.
4) Disallowing the possibility of generating spurious tuples.
----------------------------------------------------------------------------------------------------------------------------------------------
1) Imparting clear semantics to attributes in a relation.
* When we group attributes to form a relation, the attributes must have a real world meaning and proper
interpretation associated with them.
* Consider the Schema below:
EMPLOYEE [Ename | ssn | bdate | address | dnumber]
* The easier to explain the semantics of the relation, the better the relation Schema design will be.
EMPLOYEE_DETAILS [Ename | ssn | bdate | address | dnumber | dept_pos]
Guideline 1:
* Design a relational Schema so that it is easy to explain its meaning. Do not combine attributes from
multiple entity types and relationship types into a single relation.
Violating guideline 1:
EMPLOYEE_DEPT [Ename | ssn | bdate | address | dnumber | Dname | mgr_ssn]
* This combines the attributes the two real world entities EMPLOYEE and DEPARTMENT, which violates
guideline 1.
----------------------------------------------------------------------------------------------------------------------------------------------
2) Reducing the redundant information in tuples:
* One goal of Schema design is to minimize the storage space used by the base relations (and hence the
corresponding files).
* Grouping attributes into relation schemas has a significant effect on storage space.
* Storing natural joins of base relations leads to an additional problem referred to as update anomalies.
* These can be classified into insertion anomalies, deletion anomalies, and modification anomalies.
----------------------------------------------------------------------------------------------------------------------------------------------
3) NULL Values in tuples:
* NULL values lead to problems with understanding the meaning of the attributes.
* Also, it causes confusion in COUNT and SUM operators.
* Also, if NULL value comes in comparison or JOIN operations, the result will be unpredictable.
Guideline 3:
* As far as possible, avoid placing attributes in a relation whose values may frequently be NULL unless they
do not apply to the majority of the tuples.
----------------------------------------------------------------------------------------------------------------------------------------------
4) Generation of Spurious tuples:
EMP_PROJ [Ssn | Pnumber | Hours | Ename | Pname | Location]
EMP_LOCS [Ename | Plocation]
Emp_PROJ1 [Ssn | Pnumber | Hours | Pname | Pnumber]
* The relation Emp_PROJ is decomposed into two relations Emp_LOCS and Emp_PROJ1. But if the two
tables are joined by JOIN operation, it will generate some unexpected spurious tuples. So the joined table
will not be same as EMP-PROJ.
Guideline 4
* Design relation schema so that they can be joined with equality conditions they can be and they are
appropriately deleted on attributes to guarantee that no spurious tuples will be generated.
2) Define 1NF, 2NF, and 3NF with examples.
----------------------------------------------------------------------------------------------------------------------------------------------
Normalization
Normalization is the process of organizing data in a database to:
* Eliminate redundancy (duplicate data)
* Ensure data dependencies make sense
* Improve data integrity and efficiency
----------------------------------------------------------------------------------------------------------------------------------------------
First Normal Form (1NF)
*Each column should contain atomic (indivisible) values.
* All entries in a column must be of the same data type.
* Each row should be unique (have a unique identifier/primary key).
* No repeating groups or arrays allowed.
----------------------------------------------------------------------------------------------------------------------------------------------
2. Second Normal Form (2NF) Definition:
A table is in Second Normal Form (2NF) if it is in 1NF and all non key attributes are fully functionally
dependent on the entire primary key. In other words, there should be no partial dependency of any column
on a subset of a composite primary key.
3. Third Normal Form (3NF)
A table is in Third Normal Form (3NF) if it is in 2NF and all the attributes are functionally dependent only on
the primary key, and not on any other non-key attributes. This means there should be no transitive
dependency.
12) What is functional dependency? Write an algorithm to find minimal cover for set of functional
dependencies. Construct minimal cover M for set of functional dependencies which are:
E = { B → A, D → A, AB → D }
A functional dependency is a relationship between attributes in a relational database where the value of
one set of attributes uniquely determines the value of another set of attributes
In a relation R, an attribute Y is functionally dependent on attribute X (written as X → Y) if, for any two
tuples t1 and t2,
Example:
Consider a relation:
Student(StudentID, Name, Dept, Email)
Here:
• StudentID → Name (Each student ID corresponds to exactly one student name)
• StudentID → Email (Each student ID has one email)
• But Name → StudentID may not hold if multiple students have the same name.
Steps:
1. Split RHS:
o Ensure each FD has a single attribute on the right-hand side.
o E.g., A → BC becomes A → B, A → C
o
2. Remove Extraneous Attributes from LHS:
o For each FD X → Y, check if any attribute in X can be removed without changing the closure.
o
3. Remove Redundant FDs:
o Temporarily remove an FD and compute the closure of remaining FDs.
o If the removed FD can be derived from the rest, it's redundant.
Apply the Algorithm to Given Set:
E = { B → A, D → A, AB → D }
A functional dependency is a relationship between attributes in a relational database where the value of
one set of attributes uniquely determines the value of another set of attributes
In a relation R, an attribute Y is functionally dependent on attribute X (written as X → Y) if, for any two
tuples t1 and t2,
Example:
Consider a relation:
Student(StudentID, Name, Dept, Email)
Here:
• StudentID → Name (Each student ID corresponds to exactly one student name)
• StudentID → Email (Each student ID has one email)
• But Name → StudentID may not hold if multiple students have the same name.
1. Reflexivity Rule
If Y is a subset of X, then:
X→Y
Proof:
If you know the values of X, you naturally know the values of any subset of X.
Example:
If X = {StudentID, Name} and Y = {Name},
then {StudentID, Name} → Name holds.
2. Augmentation Rule
If:
X→Y
then for any Z,
XZ → YZ
Proof:
If X determines Y, then adding the same attributes (Z) to both sides doesn’t change the dependency.
Example:
If StudentID → Name, then
StudentID, Dept → Name, Dept
3. Transitivity Rule
If:
X → Y and Y → Z
then:
X→Z
Proof:
If X determines Y, and Y determines Z, then X indirectly determines Z.
Example:
StudentID → Name, and Name → Email
⇒ StudentID → Email
4. Union Rule
If:
X → Y and X → Z
then:
X → YZ
Proof:
From augmentation: X → Y ⇒ X → Y, X → Z ⇒ X → Z
By combining them, X → YZ
5. Decomposition Rule
If:
X → YZ
then:
X → Y and X → Z
Proof:
Since Y and Z are subsets of YZ, apply reflexivity.
4) Discuss insertion, deletion and modification anomalies. Why are they considered bad? Illustrate with
examples.
25) Explain the types of update anomalies in SQL with an example.
1. Insertion Anomaly
Insertion anomaly occurs when certain attributes cannot be inserted into the database without the
presence of some other, unnecessary data.
➤ Example:
Consider this table:
StudentID StudentName CourseID CourseName
101 Asha CS101 DBMS
Now, suppose a new course "AI" (CourseID: CS102) is introduced, but no student has enrolled yet.
You cannot insert this course into the table because it needs student details due to the structure. This
causes an insertion anomaly.
➤ Solution:
Separate into:
• Student(StudentID, StudentName)
• Course(CourseID, CourseName)
• Enrollment(StudentID, CourseID)
This allows inserting courses independently of students.
2. Deletion Anomaly
A deletion anomaly occurs when deleting a record unintentionally removes additional valuable data that
should have been kept.
➤ Example:
Using the same table:
StudentID StudentName CourseID CourseName
101 Asha CS101 DBMS
102 Raj CS102 Java
If student Raj drops out, we delete his row. But this deletion also removes information about the Java
course, even if it's still being offered.
➤ Solution:
Keep Course data in a separate table so that deleting a student doesn't affect course data.
3. Modification (Update) Anomaly
A modification anomaly occurs when a single piece of data exists in multiple places, and we must update all
of them consistently. If even one update is missed, it causes inconsistent or incorrect data.
➤ Example:
Suppose the instructor for "DBMS" changes from "Dr. Rao" to "Dr. Singh". If "DBMS" appears in multiple
rows (one for each student), we must update every occurrence.
StudentID StudentName CourseID CourseName Instructor
101 Asha CS101 DBMS Dr. Rao
102 Raj CS101 DBMS Dr. Rao
➤ Solution:
Store instructor details separately in a Course table:
Course(CourseID, CourseName, Instructor)
Data Inconsistency
Update anomalies may lead to different values for the same data.
Loss of Information
Deletion anomalies may cause important data to be lost permanently.
Incomplete Data Entry
Insertion anomalies prevent the addition of certain data unless irrelevant data is also provided.
Poor Maintainability
More time and effort is needed to manage redundant data.
Violation of Data Integrity
Anomalies often result in logically incorrect or incomplete databases.
3) Write the syntax for INSERT, UPDATE and DELETE statements in SQL and explain with suitable
examples.
1. INSERT Command The insert statement is used To add new records into a table.
➤ Syntax:
INSERT INTO table_name (column1, column2, ...)
VALUES (value1, value2, ...);
➤ Example:
-- Creating a table first
CREATE TABLE Student (
StudentID INT,
Name VARCHAR(50),
Age INT
);
-- Inserting values
INSERT INTO Student (StudentID, Name, Age)
VALUES (101, 'Asha', 20);
2. DELETE Command The delete statement is used To remove records from a table.
➤ Syntax:
DELETE FROM table_name
WHERE condition;
➤ Example:
-- Delete a specific student by ID
DELETE FROM Student
WHERE StudentID = 101;
3. UPDATE Command The update statement is used To modify existing data in a table.
➤ Syntax:
UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;
➤ Example:
-- Update name of a student
UPDATE Student
SET Name = 'Ashwini'
WHERE StudentID = 102;
5) Illustrate the following with suitable examples:
(i) Datatypes in SQL (ii) Substring Pattern Matching in SQL
----------------------------------------------------------------------------------------------------------------------------------------------
(i) Datatypes in SQL
SQL provides various data types to define the type of data that can be stored in a column of a table. Here
are some common SQL datatypes:
----------------------------------------------------------------------------------------------------------------------------------------------
● INT: Stores integer values (e.g., 100, -45).
CREATE TABLE Employees (
ID INT,
Name VARCHAR(50),
Age INT
);
----------------------------------------------------------------------------------------------------------------------------------------------
● VARCHAR(size): Stores variable-length string data (e.g., John, Database).
CREATE TABLE Students (
StudentID INT,
Name VARCHAR(100)
);
----------------------------------------------------------------------------------------------------------------------------------------------
● FLOAT: Stores floating-point numbers (e.g., 10.5, -2.75).
CREATE TABLE Products (
ProductID INT,
Price FLOAT
);
----------------------------------------------------------------------------------------------------------------------------------------------
● DATE: Stores date values in the format YYYY-MM-DD (e.g., 2023-09-20).
CREATE TABLE Orders (OrderID INT,
OrderDate DATE
);
----------------------------------------------------------------------------------------------------------------------------------------------
● BOOLEAN: Stores true/false values.
CREATE TABLE Flags (
FlagID INT,
IsActive BOOLEAN
);
----------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------
SQL provides the LIKE operator for pattern matching using wildcards, and it is commonly used to search for
substrings in string data. The two main wildcards used with LIKE are:
----------------------------------------------------------------------------------------------------------------------------------------------
Normalization
Normalization is the process of organizing data in a database to:
* Eliminate redundancy (duplicate data)
* Ensure data dependencies make sense
* Improve data integrity and efficiency
----------------------------------------------------------------------------------------------------------------------------------------------
Problems without normalization:
* Redundant data: Repeating the same information (e.g., employee name for each project)
* Update anomaly: Updating in one place but not others causes inconsistency
* Insertion anomaly: Cannot insert data unless some unrelated field is known
* Deletion anomaly: Deleting one record may delete useful data
* Improves data consistency and efficiency
----------------------------------------------------------------------------------------------------------------------------------------------
Second Normal Form (2NF) Definition:
A table is in Second Normal Form (2NF) if it is in 1NF and all non key attributes are fully functionally
dependent on the entire primary key. In other words, there should be no partial dependency of any column
on a subset of a composite primary key.
----------------------------------------------------------------------------------------------------------------------------------------------
Step 1: Identify Partial Dependencies
SSn → Ename
→ Partial dependency (only part of the key)
1) Emp_Proj_Hours
Stores hours worked on projects.
Employee(SSn, Ename)
Primary Key: SSn
----------------------------------------------------------------------------------------------------------------------------------------------
3) Project
Stores project information.
Example:
CREATE TABLE Student (
USN VARCHAR(10) PRIMARY KEY,
Sname VARCHAR(50),
Address VARCHAR(100),
Phone BIGINT,
Gender CHAR(1)
);
4. ALTER Command
The ALTER statement is used To modify the structure of a table such as adding, deleting, or modifying
columns.
➤ Syntax:
• Add a column:
ALTER TABLE table_name
ADD column_name datatype;
➤ Example:
ALTER TABLE Student
ADD Email VARCHAR(100);
➤ Syntax:
• Modify a column:
ALTER TABLE table_name
MODIFY column_name new_datatype;
➤ Example:
ALTER TABLE Student
MODIFY Age VARCHAR(10);
5. DROP Command
The DROP statement is used To permanently delete a table or database from the system.
All data and structure will be lost. This action cannot be undone
➤ Syntax:
DROP TABLE table_name;
DROP DATABASE database_name;
➤ Example:
-- Drop a table
DROP TABLE Student;
-- Drop a database
DROP DATABASE CollegeDB;
1. INSERT Command The insert statement is used To add new records into a table.
➤ Syntax:
INSERT INTO table_name (column1, column2, ...)
VALUES (value1, value2, ...);
➤ Example:
-- Creating a table first
CREATE TABLE Student (
StudentID INT,
Name VARCHAR(50),
Age INT
);
-- Inserting values
INSERT INTO Student (StudentID, Name, Age)
VALUES (101, 'Asha', 20);
2. DELETE Command The delete statement is used To remove records from a table.
➤ Syntax:
DELETE FROM table_name
WHERE condition;
➤ Example:
-- Delete a specific student by ID
DELETE FROM Student
WHERE StudentID = 101;
➤ Syntax:
UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;
➤ Example:
-- Update name of a student
UPDATE Student
SET Name = 'Ashwini'
WHERE StudentID = 102;
----------------------------------------------------------------------------------------------------------------------------------------------
Q5.a Explain the Cursor & its properties in embedded SQL with an example.
(ALSO ASKED IN M4 PYQ DEC)
A cursor is a database object used to retrieve and process rows from a query result set one at a
time.
Properties of Cursors
1. Declare: Define the cursor with a DECLARE statement, specifying the SQL query.
2. Open: Use OPEN to execute the query and create the result set.
3. Fetch: Use FETCH to retrieve individual rows from the result set.
4. Close: Use CLOSE to release resources associated with the cursor.
5. Deallocate: Optionally use DEALLOCATE to remove the cursor definition and free resources.
Example
-- Fetch rows
FETCH NEXT FROM emp_cursor INTO @emp_id, @emp_name, @salary;
* A transaction in a database is a logical unit of work that consists of one or more SQL operations (such as
INSERT, UPDATE, DELETE, or SELECT) executed as a single unit.
* A transaction must either complete entirely or not execute at all, ensuring data integrity in a multi-user
and concurrent environment.
1. ASSERTION in SQL
* An assertion is a condition or rule that must always be true for the database. It is used to enforce
constraints that involve multiple tables or complex conditions which can't be expressed using CHECK
constraints.
* If the condition in the assertion becomes false, the transaction is rolled back.
Syntax:
CREATE ASSERTION assertion_name
CHECK (condition);
Example:
Scenario: Ensure that no student is allowed with age less than 18.
CREATE ASSERTION age_check
CHECK (
NOT EXISTS (
SELECT * FROM Student
WHERE age < 18
)
);
* This assertion will prevent insertion or update of any student record with age < 18.
2. TRIGGERS in SQL
* A trigger is a special kind of stored procedure that automatically executes when a specific event (INSERT,
UPDATE, DELETE) occurs on a table.
* They can be set to execute BEFORE, AFTER, or INSTEAD OF the triggering event
Syntax (MySQL-style):
CREATE TRIGGER trigger_name
BEFORE | AFTER INSERT | UPDATE | DELETE
ON table_name
FOR EACH ROW
BEGIN
-- trigger logic
END;
Example:
Scenario: Keep a log of all deleted students in a separate table.
* This trigger will automatically store deleted student records in the log table.
18) Demonstrate the System Log in database transaction.
* The System Log also called the Transaction Log or Write-Ahead Log
* Log keeps track of all transaction operations that affect the values of database items. This information
may be needed to recovery from transaction failures.
* The log is kept on disk, so it is not affected by any type of failure except for disk
* one or more main memory buffers hold the last part of the log file, so that log entries are first added to
the main memory buffer
* When the log buffer is filled, or when certain other conditions occur, the log buffer is appended to the
end of the log file on disk.
* In addition, the log is periodically backed up to archival storage (tape) to guard against such failures
* The following are the types of entries called log records that are written to the log file
* In these entries, T refers to a unique transaction-id that is generated automatically by the system for each
transaction and that is used to identify each transaction:
➤ [Write-item, T, X, Old_value, New_value]: Indicates that transaction T has changed the value of
database item X from old_value to new_value.
➤ [Read-item, T, X]: Indicates that transaction T has read the value of database item X.
➤ [Commit, T]: Indicates that transaction T has completed successfully and affirms that its effect
can be committed (recorded permanently) to the database.
A transaction is an atomic unit of work that should either be completed in its entirety or not done at all.
For recovery purposes, the system needs to keep track of when each transaction starts, terminates, and
commits or aborts. Therefore, the recovery manager of the DBMS needs to keep track of the following
operations:
READ or WRITE: These specify read or write operations on the database items that are executed as part of
a transaction.
END TRANSACTION: This specifies that READ and WRITE transaction operations have ended and marks the
end of transaction execution.
COMMIT TRANSACTION: This signals a successful end of the transaction so that any changes (updates)
executed by the transaction can be safely committed to the database and will not be undone.
ROLLBACK (or ABORT): This signals that the transaction has ended unsuccessfully, so that any changes or
effects that the transaction may have applied to the database must be undone.
* A transaction goes into an active state immediately after it starts execution, where it can execute its READ
and WRITE operations. When the transaction ends, it moves to the partially committed state.
* At this point, some recovery protocols need to ensure that a system failure will not result in an inability to
record the changes of the transaction permanently (usually by recording changes in the system log). Once
this check is successful, the transaction is said to have reached its commit point and enters the committed
state.
* When a transaction is committed, it has concluded its execution successfully and all its changes must be
recorded permanently in the database, even if a system failure occurs.
* However, a transaction can go to the failed state if one of the checks fails or if the transaction is aborted
during its active state.
* The transaction may then have to be rolled back to undo the effect of its WRITE operations on the
database.
* The terminated state corresponds to the transaction leaving the system. The transaction information that
is maintained in system tables while the transaction has been running is removed when the transaction
terminates. Failed or aborted transactions
4) What are the views in SQL? Explain with examples.
8) Write the syntax and example of view in SQL. Explain efficient view implementation.
views
Views in SQL are virtual tables based on the result of an SQL query. They do not store data themselves but
provide a way to look at and manipulate the result of aquery as if it were a table
* It does not store data physically, but provides a logical representation of one or more tables.
Example:
Scenario: Consider a table named Student.
A stored procedure in SQL is a precompiled collection of one or more SQL statements that can be executed
as a unit. Stored procedures are used to encapsulate operations like inserting, updating, or retrieving data,
which can then be reused multiple times and maintained in the database.
DELIMITER ;
* We can create a stored procedure to insert a new employee into the table.
DELIMITER //
DELIMITER ;
* This will insert a new employee with ID 101, name 'Alice', and salary 55000 into the Employees table.
2) What do you understand by correlated Nested Queries in SQL? Explain with suitable example
Example:
Problem: Find employees who earn more than the average salary of their own department. Employees
Table:
ID Name Department Salary
1 Alice HR 40000
2 Bob HR 50000
3 Carol IT 60000
4 David IT 55000
Explanation:
• The subquery uses [Link] from the outer query.
• So it runs once for each row, computing the average salary of that employee’s department.
5) In SQL, write the usage of GROUP BY and HAVING clauses with suitable examples.
1. GROUP BY Clause
* The GROUP BY clause is used to group rows that have the same values in specified columns.
* It is typically used with aggregate functions like COUNT(), SUM(), AVG(), MAX(), or MIN().
Example:
Problem: Find the total salary paid in each department.
Employees Table:
ID Name Department Salary
1 Alice HR 40000
2 Bob HR 50000
3 Carol IT 60000
4 David IT 55000
5 Eve Finance 45000
Output:
Department TotalSalary
HR 90000
IT 115000
Finance 45000
2. HAVING Clause
The HAVING clause is used to filter groups after they have been formed by the GROUP BY clause. Unlike
WHERE (which filters rows), HAVING filters aggregated group results.
Example:
Problem: Find departments where the total salary is more than 90000.
Output:
Department TotalSalary
IT 115000
6) Discuss the types of problems that may encounter with transactions that run concurrently.
Initial X = 80
T1: READ(X) → 80
T2: READ(X) → 80
T1: X = X - 5 → 75
T1: WRITE(X)
T2: X = X + 4 → 84
T2: WRITE(X) ← overwrites T1’s update
Final X = 84 (incorrect)
Expected X = 79 (T1 subtracted 5, T2 added 4)
Problem: T2 read a dirty value (5000) that was never committed — leads to incorrect processing.
Table: Orders
Rows: [100, 200, 300]
Problem: T1 includes some updated and some original values, leading to an incorrect total.
4. Unrepeatable Read Problem
Happens when a transaction reads the same item twice and gets different values because another
transaction updated it in between.
Initial Stock = 50
T1: READ(Stock) → 50
T2: UPDATE Stock = 45
T2: COMMIT
T1: READ(Stock) → 45
* Transaction T1 expected that the value of stock stays the same while it is running.
* But it got two different values (50 and 45) for the same data.
1) Consider the following relations:
Student(Snum, Sname, Branch, level, age)
Class(Cname, meet_at, room, fid)
Enrolled(Snum, Cname)
Faculty(fid, fname, deptid)
Write the following queries in SQL. No duplicates should be printed in any of the answers.
(i) Find the names of all Juniors (level = JR) who are enrolled in a class taught by I. Teach.
(ii) Find the names of all classes that either meet in room R128 or have five or more students enrolled.
(iii) For all levels except JR, print the level and the average age of students for that level.
(iv) For each faculty member that has taught classes only in room R128, print the faculty member’s name
and the total number of classes she or he has taught.
(v) Find the names of students not enrolled in any class.
15) Determine if the following schedule is serializable and explain your reasoning:
i) T1: R(X) W(X)
T2: R(X) W(X)
T1: COMMIT
T2: COMMIT
Conflicting Operations:
• T1: W(X) and T2: R(X) → Write-Read conflict → T1 → T2
• T1: W(X) and T2: W(X) → Write-Write conflict → T1 → T2
Precedence Graph:
• Edge: T1 → T2
No cycle
Result: Conflict-Serializable
• Equivalent to serial schedule: T1 → T2
(ii) Schedule:
T1: W(X) → R(Y)
T2: R(X) → W(Y)
T1: COMMIT
T2: COMMIT
Conflicting Operations:
• T1: W(X) and T2: R(X) → Write-Read conflict → T1 → T2
• T1: R(Y) and T2: W(Y) → Read-Write conflict → T2 → T1
Precedence Graph:
• Edges:
o T1 → T2
o T2 → T1
Cycle Detected: T1 ↔ T2
Not serializable
Final Answers:
Schedule Serializable? Reason
No cycles in conflict graph (T1
(i) Yes
→ T2)
Cycle exists in conflict graph
(ii) No
(T1 → T2 → T1)
Module 5
----------------------------------------------------------------------------------------------------------------------------------------------
Pyq jun/jul -- 1
1) What is the two-phase locking protocol? How does it guarantee serializability?
2) Describe the wait-die and wound-wait protocols for deadlock prevention.
3) List and explain the four major categories of NoSQL system.
4) What is Multiple Granularity locking? How is it implemented using intention locks? Explain.
5) Discuss the following MongoDB CRUD operations with their formats: (i) Insert (ii) Delete (iii) Read
6) Briefly discuss about Neo4j data model.
----------------------------------------------------------------------------------------------------------------------------------------------
Pyq jun/jul -- 2
7) Demonstrate with example deadlock in transaction. Discuss deadlock prevention algorithm.
8) What are Binary locks? Explain with Lock and unlock operations with algorithm.
9 ) Write a short note on:
i) Properties of NoSQL system
ii) The CAP theorem
iii) Document based NoSQL system
iv) NoSQL Graph database
----------------------------------------------------------------------------------------------------------------------------------------------
pyq dec/jan
10) Explain the CAP theorem.
11) What is NoSQL graph database? Explain Neo4j.
12) Why concurrency control and recovery are needed in DBMS? Demonstrate with suitable examples
types of problems that may occur when two simple transactions run concurrently.
13) Explain basic operations CRUD in MongoDB.
14) Explain deadlock prevention protocols.
15) Briefly discuss the two-phase locking techniques for concurrency control.
----------------------------------------------------------------------------------------------------------------------------------------------
Mqp – 1
16) Demonstrate the Two phase locking protocol used for concurrency control.
17) Demonstrate the Concurrency control based on Timestamp ordering.
18) Why Concurrency control is needed? Demonstrate with an example.
19) What is NOSQL? Explain the CAP theorem.
20) What are document based NOSQL systems? Explain basic operations CRUD in MongoDB.
21) What is NOSQL Graph database? Explain Neo4j.
----------------------------------------------------------------------------------------------------------------------------------------------
Mqp – 2
22) Explain the Two phase locking protocol used for concurrency control.
23) Define Schedule? Illustrate with an example.
24) Why Concurrency control is needed? Demonstrate with an example.
25) What is NOSQL? Explain the CAP theorem.
26) What are document based NOSQL systems? basic operations CRUD in MongoDB.
27) What is NOSQL Graph database? Explain Neo4j.
----------------------------------------------------------------------------------------------------------------------------------------------
1) What is the two-phase locking protocol? How does it guarantee serializability?
Phases of 2PL
* Growing Phase: The transaction acquires all the locks it needs (e.g., shared or exclusive locks) without
releasing any locks.
* Shrinking Phase: The transaction releases all its locks without acquiring any new ones.
Example
* Consider two transactions, T1 and T2, accessing data items A and B:
• T1: Read(A), Write(B)
• T2: Write(A), Read(B)
Without 2PL, their operations could interleave, causing conflicts (e.g., T2 writes A before T1 reads A,
leading to inconsistent results). With 2PL:
Conflict Avoidance:
2PL ensures that a transaction acquires the required locks before accessing data.
This prevents other transactions from accessing the same data simultaneously, avoiding conflicts like dirty
reads or lost updates.
Locking Discipline:
Transactions follow a strict rule: acquire all locks before releasing any.
This creates a predictable access pattern, ensuring that transactions do not interfere with each other’s
critical sections.
Conflict Serializability:
The locking mechanism of 2PL avoids cycles in the precedence graph of transactions.
15) Briefly discuss the two-phase locking techniques for concurrency control.
Phases of 2PL
* Growing Phase: The transaction acquires all the locks it needs (e.g., shared or exclusive locks) without
releasing any locks.
* Shrinking Phase: The transaction releases all its locks without acquiring any new ones.
Key Features
• Conflict Prevention: Locks prevent conflicting operations (e.g., simultaneous writes or read-write
conflicts) by ensuring exclusive access to data items.
• Serializability: 2PL guarantees conflict-serializable schedules, producing results equivalent to a serial
execution of transactions by enforcing a strict access order.
• Lock Types: Shared locks allow multiple transactions to read a data item, while exclusive locks
ensure sole access for writing.
Variants of 2PL
1. Basic 2PL: Follows the two-phase rule but may release locks before commit, risking cascading
rollbacks.
2. Strict 2PL: Locks are held until the transaction commits or aborts, ensuring recoverability and
preventing cascading rollbacks.
3. Rigorous 2PL:All locks (shared and exclusive) are held until the transaction ends. Ensures
serializability and recoverability.
4. Conservative C2PL: In Conservative 2PL, a transaction pre-declares all the locks it needs before it
starts. If all required locks are available, it proceeds; otherwise, it waits without locking anything,
avoiding deadlocks completely.
19) What is NOSQL? Explain the CAP theorem.
NOSQL
* NoSQL is a type of database management system (DBMS) that is designed to handle and store large
volumes of unstructured and semi-structured data.
* Unlike traditional relational databases that use tables with predefined schemas to store data, NoSQL
databases use flexible data models that can adapt to changes in data structures and are capable of scaling
horizontally to handle growing amounts of data.
CAP theorem
It is a fundamental principle in distributed systems that describes the trade-offs between three properties:
Consistency, Availability, and Partition Tolerance. It states that a distributed system can only guarantee
two of these three properties simultaneously under network partitions.
* Consistency ensuring all nodes in the system have the same view of the data at any given time
* Availability ensures every request receives a response, even if some nodes fail.
* Partition Tolerance means the system continues to operate despite network failures that partition the
system
* CA (Consistency + Availability):
Assumes no network partition. Prioritizes consistent and available responses. Fails during partition.
Example: MySQL (single-node).
Key Features
• Nodes: Represent entities (e.g., people, products, or places).
• Edges: Represent relationships between nodes (e.g., "friend of," "purchased," or "located in").
• Properties: Attributes of nodes or edges (e.g., a person's name or a relationship's timestamp).
• Flexible Schema: No rigid schema; nodes and edges can have varying properties.
• Real-time traversal (e.g., social networks, fraud detection, recommendation engines)
Neo4j
Neo4j is the most widely used NoSQL graph database. It uses the property graph model and supports the
Cypher query language for data operations.
Features of Neo4j:
• Stores data as nodes, relationships, and properties
• Highly optimized for graph traversa
• Scalability and Performancel
• ACID-compliant transactions
• Easy to query with Cypher (SQL-like syntax for graphs)
• Neo4j typically operates as a CP system (Consistency + Partition Tolerance)
* It is widely used in applications requiring Social Networks: ecommendation Systems: Fraud Detection
Knowledge Graphs: Network Analysis:
20) What are document based NOSQL systems? Explain basic operations CRUD in MongoDB. ?
* Document-based NoSQL systems, also known as document stores, are a type of non-relational database
that store and manage data as semi-structured documents, typically in formats like JSON, BSON, or XML.
* Each document represents a record, and can contain nested structures like arrays and key-value pairs
(e.g., JSON-like { "name": "Alice", "age": 30 })
Key Features:
• Schema-less: Documents can have different fields and structures.
• Flexible: Easy to modify or update documents without altering schema.
• Indexable: Fields inside documents can be indexed for fast queries.
• Efficient for hierarchical or semi-structured data
• Most document-based NoSQL systems prioritize Availability and Partition Tolerance (AP)
Use Cases
Content Management: E-commerce: Real-Time Analytics: IOT
Example of a Document:
{
"name": "Alice",
"age": 25,
"email": "alice@[Link]",
"skills": ["Java", "MongoDB"]
}
----------------------------------------------------------------------------------------------------------------------------------------------
CRUD stands for:
Create Read Update Delete
* These are the four basic operations used to manipulate data in a MongoDB database.
1. Create
Used to insert a new document into a collection.
Syntax:
[Link]({ key: "value", ... })
Example:
[Link]({
name: "Alice",
age: 21,
course: "Computer Science"
})
2. Read (Find)
Used to retrieve documents from a collection.
Syntax:
[Link]({ query })
Example:
[Link]({ name: "Alice" })
3. Update
Used to modify existing documents.
Syntax:
[Link]({ filter }, { $set: { updatedFields } })
Example:
[Link](
{ name: "Alice" },
{ $set: { age: 22 } }
)
4. Delete
Used to remove documents from a collection.
Syntax:
[Link]({ filter })
Example:
[Link]({ name: "Alice" })
3) List and explain the four major categories of NoSQL system.
1. Document-Based Databases
Document stores manage data as semi-structured documents, typically in formats like JSON, BSON, or XML.
Sample Document:
{
"name": "Alice",
"email": "alice@[Link]",
"skills": ["Java", "Python"]
}
2. Key-Value Stores
storing data as a collection of key-value pairs, where each key is unique and maps to a value. The value can
be a string, number, or complex object
Sample Entry:
Key: "user123"
Value: { "name": "Alice", "age": 25 }
3. Column-Based Databases
Column-Based Databases stores organize data into columns rather than rows, grouping related columns
into families. Each row can have different columns, optimized for analytical queries.
Sample Relationship:
(Alice) -[:FRIENDS_WITH]-> (Bob)
----------------------------------------------------------------------------------------------------------------------------------------------
1. Schema-less Structure
o No fixed table schema; each document/record can have a different structure.
o Makes it easy to evolve the data model over time.
2. Horizontal Scalability
o Supports distribution of data across multiple servers (sharding).
o Enables easy handling of big data and high-traffic applications.
3. High Performance
o Optimized for fast read/write operations.
o Efficient for large-scale, real-time processing.
6. Built-in Caching
o Some NoSQL databases like Redis have in-memory caching features for speed.
Concurrency control in DBMS ensures that multiple transactions can execute simultaneously without
interfering with each other, and without violating data consistency and integrity.
Timestamp Ordering (TO) is a concurrency control protocol that uses timestamps to ensure serializability
(i.e., the result of concurrent transactions is the same as some serial execution order).
Each transaction is assigned a unique timestamp (TS) when it starts:
• Older transactions get smaller timestamps.
• Younger transactions get larger timestamps.
Example:
Let’s say we have:
• TS(T1) = 5
• TS(T2) = 10
• Initially: read_TS(X) = 0, write_TS(X) = 0
Step-by-Step:
1. T1: Read(X)
o TS(T1) = 5 > write_TS(X) = 0 → Allowed
o Update: read_TS(X) = 5
2. T2: Write(X)
o TS(T2) = 10 > read_TS(X) = 5
o TS(T2) = 10 > write_TS(X) = 0 → Allowed
o Update: write_TS(X) = 10
3. T1: Write(X)
o TS(T1) = 5 < write_TS(X) = 10 → Reject
o T1 is aborted to maintain consistency
Advantages:
• Ensures serializability
• No need for locks (non-blocking)
• Prevents deadlocks
12) Why concurrency control and recovery are needed in DBMS? Demonstrate with suitable examples
types of problems that may occur when two simple transactions run concurrently.
Concurrency control in DBMS ensures that multiple transactions can execute simultaneously without
interfering with each other, and without violating data consistency and integrity.
C. Unrepeatable Read
• T1: Reads a record twice
• T2: Modifies the same record between T1’s reads
T1: READ(Product Price) → ₹500
T2: UPDATE(Product Price = ₹600)
T1: READ(Product Price again) → ₹600 (value changed)
7) Demonstrate with example deadlock in transaction. Discuss deadlock prevention algorithm.
deadlock
A deadlock in a database system occurs when two or more transactions are unable to proceed because
each is waiting for the other to release a lock on a resource, creating a cycle of dependencies
Transaction T2:
LOCK(B)
LOCK(A)
UNLOCK(B)
UNLOCK(A)
1. Wait-Die Protocol
• Older transaction is allowed to wait
• Younger transaction is aborted (dies)
Rules:
• If T₁ (older) requests a resource held by T₂ (younger) → T₁ waits
• If T₂ (younger) requests a resource held by T₁ (older) → T₂ dies
Example:
• T1 (timestamp = 5), T2 (timestamp = 10)
• T1 requests a lock held by T2 → T1 waits
• T2 requests a lock held by T1 → T2 dies
2. Wound-Wait Protocol
• Older transaction wounds (forces abort) the younger one
• Younger transaction waits
Rules:
• If T₁ (older) requests a resource held by T₂ (younger) → T₂ is wounded (aborted)
• If T₂ (younger) requests a resource held by T₁ (older) → T₂ waits
Example:
• T1 (timestamp = 5), T2 (timestamp = 10)
• T1 requests a lock held by T2 → T2 is aborted (wounded)
• T2 requests a lock held by T1 → T2 waits
8) What are Binary Locks? Explain with Lock and Unlock Operations with Algorithm
Binary Lock?
A Binary Lock is the simplest locking mechanism used in concurrency control in DBMS.
Each data item can be in only one of two states:
• Locked (1) — The data item is currently in use and cannot be accessed by other transactions.
• Unlocked (0) — The data item is available for access.
Key Characteristics:
• Only one type of lock (no shared or exclusive modes).
• At most one transaction can hold the lock on a data item at a time.
• Used mainly to prevent conflicting operations.
UNLOCK(X)
{
LOCK_STATUS(X) = 0; // Unlock X
}
Example:
Assume Transaction T1 and T2 both want to access data item A.
1. T1: LOCK(A) → Success (A becomes locked)
2. T2: LOCK(A) → Waits (A already locked by T1)
3. T1: UNLOCK(A) → A becomes available
4. T2: Now LOCK(A) can proceed
23) Define Schedule? Illustrate with an example
* A Schedule in DBMS is the sequence of operations (read, write, commit, etc.) from one or more
transactions, executed in a specific order, maintaining the order of operations within each transaction.
* Schedules are used to determine how concurrent transactions interact with each other and whether the
execution maintains data consistency.
Types of Schedules:
• Serial Schedule – Transactions execute one after another without overlapping.
• Concurrent (Interleaved) Schedule – Operations of multiple transactions are mixed