Dbms Question Bank
Dbms Question Bank
UNIT - 1
1. Define Data and Information. Explain the need for
database systems.
Data
Data refers to raw facts and figures that do not have meaning by themselves.
Examples:
Numbers, names, marks, dates, etc.
Example:
85, Rahul, 20 → These are raw values without context.
Information
Information is processed or organized data that has meaning and is useful for
decision making.
Example:
“Rahul scored 85 marks in DBMS” → meaningful information.
question bank : 1
4. Data security – Authorized access only.
5. Data sharing – Multiple users can access data simultaneously.
6. Backup and recovery – Protection against data loss.
7. Integrity maintenance – Ensures correct and valid data.
Limitations
1. Data redundancy and inconsistency
Same data stored in multiple files.
Updating one file may not update others.
2. Difficulty in accessing data
Requires writing new programs for every query.
3. Data isolation
Data scattered in different formats and files.
4. Integrity problems
Hard to enforce constraints.
5. Security problems
Limited access control.
6. Concurrency issues
Multiple users updating data causes conflicts.
7. Lack of backup and recovery
Data loss risk is high.
question bank : 2
3. Compare File System and DBMS with suitable
examples.
Feature File System DBMS
Data storage Separate files Centralized database
Redundancy High Controlled
Data consistency Difficult Maintained
Security Low High
Data sharing Difficult Easy
Query processing Program dependent SQL based
Backup & recovery Limited Automatic support
Example
File System: Student details stored in separate files for library, exam, and
hostel.
DBMS: All data stored in a single database and shared by all departments.
question bank : 3
6. Concurrency control
Manages simultaneous operations.
7. Security and authorization
Access control mechanisms.
8. Backup and recovery
Protects against failures.
Disadvantages
1. High cost of software and hardware
2. Complex system
3. Requires trained personnel
4. Performance overhead for small applications
5. Database failure affects entire system
question bank : 4
6. Explain the three-tier DBMS architecture with a neat
diagram.
The three-tier architecture separates users from physical database storage.
Levels
1. External Level (View Level)
User view of data.
Different views for different users.
2. Conceptual Level (Logical Level)
Describes overall database structure.
Defines entities, relationships, constraints.
3. Internal Level (Physical Level)
Describes how data is stored physically.
question bank : 5
Levels of Data Abstraction
1. Physical Level
Lowest level.
Describes how data is stored in memory.
2. Logical Level
Describes what data is stored and relationships.
3. View Level
Highest level.
Shows only required data to users.
Types
1. Physical Data Independence
Ability to change physical storage without changing logical schema.
Example:
Changing indexing or storage method without affecting programs.
question bank : 6
9. Explain different types of data models used in
DBMS.
A data model defines how data is structured and organized.
question bank : 7
Company → Department → Employee
Advantages
Simple structure
Fast data access
Disadvantages
Rigid structure
Difficult many-to-many relationships
Basic Concepts
1. Relation (Table)
A table that stores data in rows and columns.
question bank : 8
Example: STUDENT table.
2. Tuple (Row)
A single record in a table.
Example: One student’s details.
3. Attribute (Column)
A property of an entity.
Example: StudentID, Name, Age.
4. Domain
Set of allowed values for an attribute.
5. Degree
Number of attributes in a relation.
6. Cardinality
Number of tuples in a relation.
Advantages
Simple structure.
Easy data manipulation using SQL.
Reduced redundancy.
Data independence.
question bank : 9
12. Define ER model. Explain entities and attributes
with examples.
ER Model
The Entity–Relationship (ER) Model is a conceptual data model used to design
databases by representing entities and relationships between them.
Entity
An entity is a real-world object that can be uniquely identified.
Examples: Student, Employee, Book.
Types:
Strong entity
Weak entity
Attribute
An attribute describes properties of an entity.
Example:
Student → StudentID, Name, Age, Address.
Example
Entity: STUDENT
Attributes: RollNo, Name, Department
question bank : 10
Can be divided into sub-parts.
Example: Address → Street, City, PIN.
3. Single-valued Attribute
Has only one value.
Example: Date of Birth.
4. Multi-valued Attribute
Can have multiple values.
Example: Phone numbers.
5. Derived Attribute
Derived from other attributes.
Example: Age derived from DOB.
6. Key Attribute
Uniquely identifies an entity.
Example: StudentID.
Types of Relationships
1. One-to-One (1:1)
One entity related to one entity.
Example: Person – Passport.
2. One-to-Many (1:N)
question bank : 11
One entity related to many entities.
Example: Department – Employees.
3. Many-to-Many (M:N)
Many entities related to many entities.
Example: Student – Course.
Relationship Constraints
Cardinality constraint
Participation constraint
Participation Constraint
Specifies whether participation is mandatory or optional.
1. Total Participation
Every entity must participate.
Example: Every employee works in a department.
2. Partial Participation
question bank : 12
Participation is optional.
Example: Not every employee manages a project.
Characteristics
Does not have a primary key.
Depends on strong entity.
Has partial key.
Example
Employee (strong entity)
Dependent (weak entity)
Dependent cannot exist without employee.
Specialization
Process of dividing a higher-level entity into lower-level entities based on
characteristics.
Example:
Employee → Manager, Engineer.
Generalization
Process of combining lower-level entities into a higher-level entity.
question bank : 13
Example:
Car and Bike → Vehicle.
Advantages
Better representation of real-world data.
Reduces redundancy.
Attributes
Book(BookID, Title, Author, Publisher)
Member(MemberID, Name, Address)
Relationships
question bank : 14
Member borrows Book
Librarian issues Book
Explanation
One member can borrow many books.
One book can be issued to one member at a time.
Attributes
Customer(CustomerID, Name, Address)
Account(AccountNo, Type, Balance)
Relationships
Customer owns Account
question bank : 15
Branch maintains Account
Customer takes Loan
Explanation
A customer can have multiple accounts.
A branch maintains many accounts.
Customers can take loans from banks.
UNIT - 2
1. Explain the basic concepts of the relational model.
The relational model represents data in the form of tables called relations. Each
relation consists of rows and columns.
Basic Concepts
1. Relation
A table containing data.
Example: STUDENT table.
2. Tuple
A row in a relation representing a single record.
question bank : 16
3. Attribute
A column in a relation describing a property.
4. Domain
Set of allowed values for an attribute.
5. Degree
Number of attributes in a relation.
6. Cardinality
Number of tuples in a relation.
7. Relational Schema
Structure of a relation.
Example:
question bank : 17
STUDENT(StudentID, Name, Age)
Degree = 3
Types of Keys
1. Super Key
Set of attributes that uniquely identify a tuple.
2. Candidate Key
Minimal super key.
3. Primary Key
Selected candidate key used for identification.
4. Alternate Key
Candidate keys not chosen as primary key.
5. Foreign Key
Attribute that refers to primary key of another table.
6. Composite Key
Key made of more than one attribute.
Example:
STUDENT(StudentID, Email)
question bank : 18
Types
1. Domain Constraint
Attribute values must belong to a valid domain.
2. Entity Integrity Constraint
Primary key cannot be NULL.
3. Referential Integrity Constraint
Foreign key must match primary key value.
4. Key Constraint
No duplicate primary key values.
Referential Integrity
Ensures relationship consistency between tables.
Foreign key must refer to existing primary key.
Example:
DeptID in EMPLOYEE must exist in DEPARTMENT table.
question bank : 19
Relational Schema
The logical design or structure of a database.
Example:
Schema
Overall structure of database.
Does not change frequently.
Instance
Actual data stored in database at a particular time.
Changes frequently.
Basic Operations
Selection (σ)
Projection (π)
Union (∪)
Set Difference (−)
Cartesian Product (×)
Join (⨝)
Significance
Forms theoretical foundation of SQL.
question bank : 20
Used in query optimization.
Helps in database design.
σ condition (Relation)
Example:
Select students from CSE department:
Projection (π)
Selects specific columns.
Syntax:
π attribute (Relation)
Example:
question bank : 21
Union (∪)
Combines tuples from two relations.
Condition:
Same number of attributes.
Same domains.
Example:
R ∪ S
R − S
Intersection (∩)
Returns common tuples in both relations.
Example:
R ∩ S
question bank : 22
R × S
Types of Joins
1. Theta Join (θ-Join)
Join condition uses comparison operators (=, <, >, ≤, ≥, ≠).
Example:
1.
2. Equi Join
Join condition uses equality (=) only.
Duplicate columns are retained.
3. Natural Join
question bank : 23
Automatically joins relations based on common attributes.
Duplicate columns are removed.
4. Outer Join
Includes unmatched tuples.
Types:
Left Outer Join
Right Outer Join
Full Outer Join
Examples
1. Find names of students in CSE department
1.
2. Find employee names with salary > 50000
1.
2. Find students and their department names
question bank : 24
Tuple Relational Calculus (TRC) is a non-procedural query language where
queries specify what to retrieve, not how.
It uses tuple variables.
General Form
{ t | P(t) }
where
t = tuple variable
P(t) = condition
Example
Find names of students in CSE:
General Form
{ <x1, x2, … xn> | P(x1, x2, … xn) }
Example
Find names of students in CSE:
question bank : 25
Relational Algebra Relational Calculus
Procedural language Non-procedural language
Specifies how to retrieve data Specifies what to retrieve
Uses operations Uses logical expressions
Based on algebra Based on predicate logic
Foundation of query execution Foundation of query specification
Features
Can perform selection, projection, and joins.
Supports set operations.
Can retrieve complex query results.
Equivalent in expressive power to relational calculus.
Importance
Forms theoretical basis of SQL.
Used in query optimization.
question bank : 26
18. Convert SQL queries into relational algebra
expressions.
Examples
1. SQL:
Relational Algebra:
1. SQL:
Relational Algebra:
1. SQL:
Relational Algebra:
question bank : 27
Find names of students older than 20:
Example 2 (DRC)
Find employee names with salary greater than 40000:
Importance
1. Easy data retrieval.
2. Data manipulation (insert, update, delete).
3. Reduces programming effort.
4. Ensures data independence.
5. Supports complex queries.
6. Helps in decision making.
7. Provides user-friendly interaction.
UNIT - 3
1. Explain the features and advantages of SQL.
SQL (Structured Query Language)
SQL is a standard language used to create, manage, and manipulate relational
databases.
question bank : 28
Features of SQL
1. Simple and easy to learn.
2. Standardized language.
3. Supports data definition and manipulation.
4. Supports integrity constraints.
5. Provides security and authorization.
6. Supports complex queries.
7. Portable across database systems.
Advantages of SQL
Fast data retrieval.
Reduced programming effort.
Supports multiple users.
Ensures data consistency.
Easy database management.
Salary INT
question bank : 29
CHAR(n)
VARCHAR(n)
Example:
Name VARCHAR(50)
DOB DATE
DDL Commands
1. CREATE
Creates database or table.
1.
question bank : 30
2. ALTER
Modifies table structure.
1.
2. DROP
Deletes table.
1.
2. TRUNCATE
Removes all records from table.
Syntax
CREATE TABLE TableName(
ColumnName DataType Constraint
);
Example
CREATE TABLE STUDENT(
StudentID INT PRIMARY KEY,
Name VARCHAR(50) NOT NULL,
question bank : 31
Age INT,
Dept VARCHAR(20)
);
Common Constraints
PRIMARY KEY
FOREIGN KEY
NOT NULL
UNIQUE
CHECK
DEFAULT
Foreign Key
Refers to primary key of another table.
Maintains relationship between tables.
Example:
DeptID INT,
FOREIGN KEY (DeptID)
question bank : 32
REFERENCES DEPARTMENT(DeptID)
Commands
1. INSERT
1. UPDATE
UPDATE STUDENT
SET Dept='IT'
WHERE StudentID=1;
1. DELETE
UPDATE
Modifies existing records.
question bank : 33
UPDATE STUDENT
SET Dept='ECE'
WHERE StudentID=2;
DELETE
Removes records.
Syntax
SELECT column_list
FROM table_name
WHERE condition
GROUP BY column
HAVING condition
ORDER BY column;
Clauses
SELECT → columns to retrieve
FROM → table name
WHERE → condition
GROUP BY → grouping rows
HAVING → condition on groups
ORDER BY → sorting result
question bank : 34
9. Explain WHERE, ORDER BY, and DISTINCT clauses.
WHERE Clause
Filters rows based on condition.
ORDER BY Clause
Sorts result in ascending or descending order.
DISTINCT Clause
Removes duplicate values.
1. SUM()
question bank : 35
1. AVG()
1. MAX()
1. MIN()
Example
HAVING Clause
The HAVING clause is used to apply conditions on groups created by GROUP BY.
Example
question bank : 36
SELECT Dept, COUNT(*)
FROM STUDENT
GROUP BY Dept
HAVING COUNT(*) > 5;
Types of Joins
1. INNER JOIN
Returns matching rows from both tables.
1.
2. LEFT OUTER JOIN
Returns all rows from left table and matching rows from right table.
3. RIGHT OUTER JOIN
Returns all rows from right table and matching rows from left table.
4. FULL OUTER JOIN
Returns all records when there is a match in either table.
question bank : 37
INNER JOIN DEPARTMENT D
ON [Link] = [Link];
Example
SELECT Name
FROM EMPLOYEE
WHERE Salary >
(SELECT AVG(Salary) FROM EMPLOYEE);
The inner query calculates average salary, and the outer query selects employees
earning more than average.
SELECT Name
FROM STUDENT
WHERE DeptID IN
(SELECT DeptID FROM DEPARTMENT);
question bank : 38
ANY Operator
Condition is true if it satisfies any value returned by subquery.
SELECT Name
FROM EMPLOYEE
WHERE Salary > ANY
(SELECT Salary FROM EMPLOYEE WHERE Dept='HR');
ALL Operator
Condition must satisfy all values returned by subquery.
SELECT Name
FROM EMPLOYEE
WHERE Salary > ALL
(SELECT Salary FROM EMPLOYEE WHERE Dept='HR');
Types
1. UNION
Combines results and removes duplicates.
1.
2. UNION ALL
Includes duplicates.
question bank : 39
3. INTERSECT
Returns common rows.
4. EXCEPT (MINUS)
Returns rows present in first query but not in second.
Advantages
Improves security.
Simplifies complex queries.
Provides data abstraction.
Restricts data access.
Limitations
Performance may decrease.
Limited update capability.
Depends on base tables.
question bank : 40
CREATE VIEW EMP_VIEW AS
SELECT EmpName, Salary
FROM EMPLOYEE;
Updating a View
UPDATE EMP_VIEW
SET Salary = 50000
WHERE EmpName='Rahul';
Benefits
Improves performance.
Reduces network traffic.
Reusable code.
Better security.
Easier maintenance.
question bank : 41
20. Explain embedded SQL and its applications.
Embedded SQL
SQL statements written inside a host programming language such as C, Java, or
Python.
Applications
Application development.
Banking systems.
Online reservation systems.
Enterprise applications.
STUDENT_MARKS Table
CREATE TABLE STUDENT_MARKS(
StudentId INT,
Subject VARCHAR(30),
question bank : 42
Marks INT CHECK (Marks >= 0),
Semester INT,
FOREIGN KEY (StudentId)
REFERENCES STUDENT(StudentId)
);
Queries
a) Count employees grouped by department whose salary is between 25000
and 60000
question bank : 43
WHERE Salary BETWEEN 25000 AND 60000
GROUP BY DeptId;
b) Retrieve employee names starting with ‘S’ and exactly six characters
SELECT EmpName
FROM EMPLOYEE
WHERE EmpName LIKE 'S_____';
SELECT *
FROM EMPLOYEE
WHERE Designation = 'Team Lead';
SELECT *
FROM EMPLOYEE
WHERE ProjectId IN
(
SELECT ProjectId
FROM EMPLOYEE
GROUP BY ProjectId
HAVING COUNT(*) > 1
);
UNIT - 4
1. Define functional dependency with suitable
examples.
question bank : 44
A Functional Dependency (FD) describes the relationship between attributes in a
relation.
If attribute A determines attribute B, then B is functionally dependent on A.
Notation
A → B
(Read as A determines B)
Example
STUDENT(StudentID, Name, Dept)
{A, B} → A
StudentID → Name
question bank : 45
(StudentID, Subject) → Marks
4. Partial Dependency
When an attribute depends only on part of a composite key.
Example:
5. Transitive Dependency
If A → B and B → C, then A → C.
Example:
StudentID → DeptID
DeptID → DeptName
Notation
X⁺
Purpose
To find candidate keys.
To check functional dependencies.
Example
R(A, B, C)
question bank : 46
FDs: A → B, B → C
Closure of A:
A⁺ = {A, B, C}
Types
1. Lossless Join Decomposition
Original relation can be reconstructed without loss of information.
2. Lossy Decomposition
Some information is lost after decomposition.
Condition
Common attribute must be a key in at least one relation.
Example
R(A, B, C)
Decompose into:
R1(A, B) and R2(B, C)
If B is key, decomposition is lossless.
question bank : 47
Dependency preservation means all functional dependencies can be enforced
without joining decomposed relations.
Importance
Improves efficiency.
Avoids expensive joins.
Maintains data consistency.
Example
If FD A → B exists, it should remain enforceable after decomposition.
After 1NF
StudentID Phone
1 9876
1 8765
question bank : 48
Example
ENROLL(StudentID, Subject, StudentName, Marks)
FD:
After 2NF
Split into:
STUDENT(StudentID, StudentName)
ENROLL(StudentID, Subject, Marks)
Example
STUDENT(StudentID, DeptID, DeptName)
FD:
StudentID → DeptID
DeptID → DeptName
After 3NF
STUDENT(StudentID, DeptID)
DEPARTMENT(DeptID, DeptName)
question bank : 49
10. Explain Boyce-Codd Normal Form (BCNF).
A relation is in BCNF if:
For every functional dependency,
X → Y
Example
If non-key attribute determines another attribute, it violates BCNF.
Notation
A →→ B
Example
question bank : 50
STUDENT(StudentID, Phone, Skill)
If phone numbers and skills are independent:
StudentID →→ Phone
StudentID →→ Skill
Solution
Decompose into:
STUDENT_PHONE(StudentID, Phone)
STUDENT_SKILL(StudentID, Skill)
Example
STUDENT(StudentID, Phone, Skill)
Since:
StudentID →→ Phone
StudentID →→ Skill
After 4NF
STUDENT_PHONE(StudentID, Phone)
STUDENT_SKILL(StudentID, Skill)
question bank : 51
14. Explain Join Dependency and Fifth Normal Form
(5NF).
Join Dependency
A join dependency exists when a relation can be reconstructed by joining multiple
smaller relations.
Example
SUPPLIER(Product, Project, Supplier)
If relationships are independent, relation can be decomposed into smaller tables.
Components
1. Primary Storage
Main memory (RAM).
Fast but temporary.
2. Secondary Storage
Hard disk or SSD.
Permanent storage.
3. Buffer Manager
Transfers data between disk and memory.
4. File Manager
question bank : 52
Manages disk space allocation.
Secondary Storage
Hard disk, SSD.
Permanent storage.
Large capacity.
Slower than primary memory.
Types
1. Heap File Organization
Records stored randomly.
Fast insertion.
2. Sequential File Organization
Records stored in sorted order.
Efficient for sequential access.
3. Indexed File Organization
Uses index for fast retrieval.
question bank : 53
4. Hashed File Organization
Uses hash function for storage location.
Process
Address = Hash(Key)
Advantages
Fast data retrieval.
Direct access.
Disadvantages
Collision problem.
Difficult range queries.
Types
1. Primary Index
Based on primary key.
2. Secondary Index
Based on non-key attribute.
3. Clustering Index
Data stored physically in order.
question bank : 54
Advantages
Faster searching.
Reduced disk access.
Properties
All leaves at same level.
Nodes contain keys and pointers.
Supports search, insertion, deletion.
B+ Tree
An extension of B-tree.
Properties
Data stored only in leaf nodes.
Leaf nodes are linked.
Faster range queries.
B+ Tree
question bank : 55
Data stored only in leaf nodes.
Internal nodes store only keys.
Leaf nodes linked sequentially.
Comparison
B-Tree B+ Tree
Data in all nodes Data only in leaf nodes
Slower range queries Faster range queries
Less efficient indexing More efficient indexing
Leaves not linked Leaves linked
Steps (Summary)
1. Insert 15 → root.
2. Insert 5, 1 → node fills.
3. Split when overflow occurs.
4. Continue inserting and splitting.
question bank : 56
Given:
R = {P, Q, R, S, T}
FDs = { P → QR, RQ → S, Q → T, T → P }
P⁺ = {P, Q, R, S, T}
Candidate Keys
P
Q
T
(All determine entire relation)
Prime Attributes
Attributes that are part of candidate key:
P, Q, T
question bank : 57
R = {A, B, C, D, E, F}
FDs = { A → BC, B → D, CD → E, E → F }
A⁺ = {A, B, C, D, E, F}
UNIT - 5 :
1. Explain query processing steps in DBMS.
Query processing refers to the steps followed by DBMS to execute a user query
efficiently.
question bank : 58
DBMS chooses the most efficient execution plan.
3. Query Evaluation
Execution of optimized query to produce result.
Flow
SQL Query → Parser → Optimizer → Execution Engine → Result
Cost Factors
Disk I/O operations
CPU time
Memory usage
Number of records processed
Working
Multiple execution plans are generated.
Cost of each plan is estimated.
Lowest cost plan is selected.
Advantages
Improves performance.
Reduces execution time.
question bank : 59
Types
1. Materialization
Intermediate results stored temporarily.
2. Pipelining
Output of one operation directly used by next operation without storing.
Comparison
Materialization uses more memory.
Pipelining is faster and efficient.
question bank : 60
Nested loop join
Sort-merge join
Hash join
Example
Bank transfer:
Debit from account A
Credit to account B
Both operations must succeed together.
Properties
Executed completely or not at all.
question bank : 61
7. Explain transaction states with diagram.
A transaction passes through different states during execution.
Transaction States
1. Active – Transaction is executing.
2. Partially Committed – Final statement executed.
3. Committed – Changes permanently saved.
4. Failed – Execution unsuccessful.
5. Aborted – Transaction rolled back.
6. Terminated – Transaction finished.
Problems
1. Lost Update
One update overwrites another.
2. Dirty Read
Reading uncommitted data.
3. Non-repeatable Read
Same data gives different results.
4. Phantom Read
question bank : 62
New records appear during execution.
Types of Locks
1. Shared Lock (Read Lock)
Multiple transactions can read.
2. Exclusive Lock (Write Lock)
Only one transaction can write.
Advantages
Maintains consistency.
Prevents simultaneous conflicting updates.
Phases
1. Growing Phase
Transaction acquires locks.
No locks released.
2. Shrinking Phase
Locks released.
No new locks acquired.
Advantages
Prevents conflicts.
Ensures consistency.
question bank : 63
Disadvantage
May lead to deadlock.
Example
Transaction T1 holds resource A and waits for B.
Transaction T2 holds resource B and waits for A.
Both wait forever → Deadlock.
Working
question bank : 64
Older transaction gets priority.
Operations executed according to timestamp order.
Rules
Read and write operations allowed only if timestamp order is maintained.
Violating transaction is rolled back.
Advantages
Deadlock-free.
Simple implementation.
Types of Failures
Transaction failure
System crash
Disk failure
Functions
Restore database to consistent state.
Undo incomplete transactions.
Redo committed transactions.
Log Entries
Transaction start
question bank : 65
Data modification
Commit or rollback
Types
1. Deferred Update
Changes recorded after commit.
2. Immediate Update
Changes recorded immediately.
Advantages
Reliable recovery.
Maintains data consistency.
Working
Original pages remain unchanged.
Updates made on shadow pages.
On commit, shadow pages replace original pages.
Advantages
No need for log file.
Fast recovery.
Disadvantages
High memory usage.
Fragmentation problem.
question bank : 66
16. Explain checkpoint mechanism.
Checkpoint is a mechanism used to reduce recovery time.
Working
DBMS periodically saves database state.
All committed transactions written to disk.
Recovery starts from last checkpoint.
Advantages
Faster recovery.
Reduces log scanning time.
Functions
Loads required pages into memory.
Replaces pages when memory is full.
Reduces disk I/O operations.
Benefits
Improves performance.
Efficient memory utilization.
Techniques
1. Log-based Recovery
question bank : 67
Uses log file to redo or undo transactions.
2. Checkpointing
Recovery starts from last checkpoint.
3. Shadow Paging
Uses shadow copies of data pages.
Types
1. Full Backup
Entire database copied.
2. Incremental Backup
Only changed data backed up.
3. Differential Backup
Changes since last full backup.
Importance
Protects against data loss.
Supports disaster recovery.
Importance
1. Maintains data consistency.
2. Ensures ACID properties.
question bank : 68
3. Handles concurrent transactions safely.
4. Provides recovery from failures.
5. Prevents data corruption.
6. Ensures reliable multi-user access.
question bank : 69