Database Systems: Entities, Normalization, and SQL
Database Systems: Entities, Normalization, and SQL
Q1) Define an Entity and Attribute. Explain the different types of attributes
Ans: Definition:
1. Entity:
An Entity is an object or concept in the real world that can be identified and stored in a
database.
It represents a person, place, thing, or event about which data is collected.
2. Attribute:
An Attribute is a property or characteristic of an entity that describes it.
Each attribute holds some value for the entity.
Example: For entity Student, attributes can be Student_ID, Name, Age, Address.
✅ In short:
Entity = Real-world object.
Attribute = Property of an entity.
Types = Simple, Composite, Derived, Multi-valued, Key, and Optional.
Q2) Define and differentiate the following relational algebra operators with
suitable example
1. Cartesian product 2. Natural join
Ans: 1. Cartesian Product (×)
Definition:
The Cartesian Product in relational algebra is a binary operation that combines
every tuple of one relation with every tuple of another relation.
It is also known as the cross product.
Notation:
R×S
Result:
If relation R has m tuples and relation S has n tuples, then the result of R × Swill
have m × n tuples.
The resulting relation contains all attributes of both relations.
2. Natural Join (⋈)
Definition:
The Natural Join is a special type of join that combines two relations based on
all common attributes (attributes with the same name).
It automatically matches and merges the tuples having equal values in the
common attributes.
Notation:
R⋈S
Result:
It eliminates duplicate columns of the common attributes.
✅ In short:
Cartesian Product (×) → combines all tuples without condition.
Natural Join (⋈) → combines tuples with same values in common
attributes.
Q3) What is relational algebra? Explain basic operations along with symbols
of relational algebra.
Ans: Relational Algebra
Definition:
Relational Algebra is a procedural query language used in Database
Management Systems (DBMS) to retrieve data from relational databases.
It uses mathematical operations on relations (tables) to produce new relations
as results.
It tells how to obtain the result (unlike relational calculus which tells what to
obtain).
Example:
Let
Employee(EmpID, Name, Dept, Salary)
Department(Dept, Manager)
To find names of employees working in ‘CSE’ department:
π Name ( σ Dept ¿ CS E ( Employee ))
' '
✅ Summary:
Relational Algebra provides a foundation for SQL queries and ensures that
database operations are based on mathematical principles, making data
retrieval precise and structured
Q4) What is view what are its advantages explain views in SQL with example.
Ans: 🌐 What is a View in SQL?
A View in SQL is a virtual table that is based on the result of a SELECT query.
It does not store data physically — instead, it displays data stored in one or
more tables.
You can think of it as a saved SQL query that can be used like a table.
✅ Advantages of Views
1. Data Security:
Views can hide sensitive columns (like salary or password) from users.
Example: Only allow users to see names and departments, not salaries.
2. Simplifies Complex Queries:
You can save a complex query as a view and use it easily without
rewriting the SQL every time.
3. Logical Data Independence:
Changes in table structure (like adding columns) do not affect views
directly.
4. Data Consistency:
Since the view always shows the latest data from the underlying tables, it
stays up to date.
5. Reusability:
Once created, a view can be used in multiple queries just like a table.
Q5) What is normalization? Why we need to normalize the database tables.
Ans: What is Normalization?
Normalization is a process in database design used to organize data efficiently
by dividing large tables into smaller, related tables. It aims to eliminate data
redundancy (repetition of data) and ensure data integrity (accuracy and
consistency).
In simple terms, normalization restructures a database so that each piece of
data is stored only once, and relationships between data are maintained using
foreign keys.
Why We Need to Normalize Database Tables
Normalization is important for several reasons:
1. To Reduce Data Redundancy
o It prevents storing the same data in multiple places.
o Example: Storing a student's department name in every student
record is redundant — instead, we can store it in a separate
department table.
2. To Improve Data Integrity
o Ensures that data is consistent and accurate.
o Changes made in one place automatically reflect everywhere
(through relationships).
3. To Avoid Anomalies
o Insertion Anomaly: Difficulty adding new data due to missing
information.
o Updation Anomaly: Same data must be updated in multiple
places.
o Deletion Anomaly: Deleting one record unintentionally removes
related useful data.
4. To Simplify Queries and Maintenance
o A normalized database is easier to update, maintain, and expand.
5. To Improve Storage Efficiency
o Reduces unnecessary duplication, saving disk space.
✅ In summary:
Normalization is the process of organizing database tables to reduce
redundancy, avoid anomalies, and maintain data integrity.
Q6) Write the SQL syntax for the following with the example
1. Select 2. Alter 3. Update
Ans:
Q7) Explain 1st,2nd and3rd normal form with the help of suitable example
🔹 What is Normalization?
3. Proper Normalization
The design should follow normal forms (1NF, 2NF, 3NF, BCNF) to
eliminate redundancy and dependency problems.
This ensures each attribute depends only on the key, the whole key, and
nothing but the key.
4. Data Independence
The structure of data should be independent of how data is accessed or
stored.
Changes in one part of the database should not affect other parts or
applications using it.
✅ In summary:
A good relational design is normalized, consistent, flexible, secure, and
efficient, ensuring accurate data storage and easy retrieval without redundancy
or anomalies.
Problems:
1. Overflow buckets:
When a bucket becomes full, extra records are placed in overflow
buckets. This can slow down search operations.
2. Wasted space:
If the number of records decreases, some buckets may remain
underfilled.
3. Not suitable for databases that grow or shrink frequently.
🔹 Dynamic Hashing
Definition:
In dynamic hashing, the number of buckets changes dynamically (increases or
decreases) as the number of records in the database changes.
How It Works:
It uses a directory that grows or shrinks dynamically.
The hash function produces a large binary number.
Only a certain number of leading bits are used to determine the bucket.
When a bucket overflows, the directory (and possibly the hash function
bits) is expanded.
Techniques Used:
Extendible Hashing
Linear Hashing
Advantages:
1. Efficiently handles growing and shrinking databases.
2. Reduces overflow problems.
3. Maintains good search performance even as data changes.
Q10) Define transaction and their properties with suitable example
Ans: Definition of Transaction in Database System:
A transaction in a database is a sequence of one or more SQL operations (like
insert, update, delete, select) that are executed as a single logical unit of work.
A transaction ensures that either all operations are completed successfully, or
none are applied, maintaining the consistency of the database.
👉 In short:
Transaction = A logical unit of work performed on a database.
Example:
Suppose a bank transfer occurs from Account A to Account B for ₹1000.
This operation involves two steps:
1. Debit ₹1000 from Account A
2. Credit ₹1000 to Account B
If both steps succeed → Transaction is committed
If any step fails → Transaction is rolled back
SQL Example:
✅ Summary:
Transaction: A group of operations executed as a single unit.
ACID properties: Ensure reliability and correctness of transactions.
Example: Bank transfer (Debit + Credit) demonstrates all four ACID
properties.
Basic Idea:
Each transaction T gets a unique timestamp (TS(T)) when it begins.
Each data item Q in the database keeps two timestamps:
1. W-timestamp(Q): The largest timestamp of any transaction that
successfully wrote Q.
2. R-timestamp(Q): The largest timestamp of any transaction that
successfully read Q.
The protocol uses these timestamps to decide whether a transaction can read
or write a data item or must abort (rollback).
Rules of Timestamp Ordering Protocol:
1. For Read Operation (T tries to read Q):
o If TS(T) < W-timestamp(Q) →
T is too late (a newer transaction has already written Q).
➤ Reject (abort) T and rollback.
o Else →
Allow T to read Q, and
Set R-timestamp(Q) = max(R-timestamp(Q), TS(T)).
2. For Write Operation (T tries to write Q):
o If TS(T) < R-timestamp(Q) →
A newer transaction has already read Q, so writing now would
violate order.
➤ Reject (abort) T.
o If TS(T) < W-timestamp(Q) →
A newer value of Q already exists, so this write is outdated.
➤ Reject (abort) T.
o Else →
Allow T to write Q, and
Set W-timestamp(Q) = TS(T).
Advantages:
✅ Ensures serializability automatically.
✅ No deadlocks, since no transaction waits; instead, older ones are simply
rolled back.
✅ Simple to implement using system clock timestamps.
Disadvantages:
❌ High rollback rate, especially if older transactions frequently conflict with
newer ones.
❌ Starvation possible (old transactions may keep aborting).
❌ Requires precise and unique timestamps.
Types of Timestamp Protocols:
1. Basic Timestamp Ordering (BTO) – follows the rules above strictly.
2. Strict Timestamp Ordering (STO) – a transaction delays writes until all
conflicting transactions commit or abort.
3. Thomas’s Write Rule – a relaxation of BTO that ignores outdated writes
instead of aborting the transaction.
In Short:
Timestamp-based protocol ensures transactions execute in chronological
order of their timestamps to maintain database consistency and serializability
without causing deadlocks.
Data Independence
Logical Data Independence:
Changes in the conceptual schema do not affect the external schemas or
user views.
(e.g., adding a new attribute in a table should not affect user views.)
Physical Data Independence:
Changes in internal schema (storage structure, indexing, etc.) do not
affect conceptual schema.
(e.g., changing file organization from heap to hash should not affect
logical schema.)
Q14) Explain in detail about various key constraints used in database system.
Ans: 🔑 Key Constraints in Database Systems
In a Database Management System (DBMS), key constraints are rules that
ensure uniqueness and identification of records in a table. These constraints
help maintain the integrity and consistency of data.
Q15) Discuss the main characteristics of the database approach and specify
how it differs from traditional file system?
Ans: ChatGPT said:
Main Characteristics of the Database Approach
The database approach is a modern way of managing data using a Database
Management System (DBMS). It organizes data in an integrated and structured
manner, allowing easy access, sharing, and manipulation.
Here are the main characteristics:
1. Data Integration and Centralization:
o All organizational data is stored in a single database.
o Eliminates data scattered in separate files.
2. Data Independence:
o The structure of the data can change without affecting the
application programs.
o Two types:
Logical data independence: Change in schema doesn’t
affect applications.
Physical data independence: Change in physical storage
doesn’t affect logical structure.
3. Data Sharing:
o Multiple users and applications can access the same data
concurrently.
o DBMS manages concurrent access and ensures consistency.
4. Reduced Data Redundancy:
o Common data is stored only once and shared, reducing
duplication.
5. Data Consistency:
o Since data redundancy is reduced, updates are consistent across
all users.
6. Data Security and Authorization:
o Access control mechanisms restrict unauthorized access.
o Users can be assigned specific privileges.
7. Data Integrity:
o Constraints (like primary key, foreign key) ensure accuracy and
validity of data.
8. Backup and Recovery:
o Automatic recovery and backup features protect data from
failures.
9. Query Processing and Data Manipulation:
o DBMS provides high-level languages like SQL for data retrieval and
manipulation
Q16) Write a short notes on
i) Foreign Key ii) Relation state iii) Database schema.
Ans:
Q17) account(account_number, branch_name, balance)
branch (branch_name, branch_city, assets)
customer (customer_name ,customer_street, customer_city)
loan (loan_number, branch_name, amount)
depositor((customer_name, account_number)
borrower(customer_name, loan_number)
Write the following queries in SQL:
1)For all customers who have a loan from the bank, find their names, loan
numbers, and loan amount.
2) Find the customer names, loan numbers, and loan amounts, for all
loans at the Panvel branch.
3)Find the names of all branches that have assets greater than those of at
least one branch located in Mumbai.
4)Find the average account balance of those branches where the account
balance is greater than Rs. 1500.
5) Find the maximum across all branches of the total balance at each
branch.
Ans:
Q18) Write the SQL syntax for the following with example:
1)SELECT 2) ALTER 3)UPDATE
Ans:
Q19) Write an SQL query for the following:
a)To create a table of Hospital database with minimum 4 fields
b) To insert two records
c) To add new field
d)To display all records
Ans:
Q20) What are JOINS? Explain INNER JOIN and OUTER JOIN.
Ans: 💡 JOINS in SQL
Definition:
A JOIN in SQL is used to combine data from two or more tables based on a
related column between them (usually a primary key–foreign key
relationship).
It helps retrieve meaningful information spread across multiple tables.
🔹 Types of Joins
1. INNER JOIN
2. OUTER JOIN
o LEFT OUTER JOIN
o RIGHT OUTER JOIN
o FULL OUTER JOIN
3. CROSS JOIN
4. SELF JOIN
🔸 1. INNER JOIN
Definition:
The INNER JOIN returns only the rows that have matching values in both tables.
🔸 2. OUTER JOIN
Definition:
The OUTER JOIN returns all rows from one or both tables, even if there is no matching
record in the other table.
➤ a) LEFT OUTER JOIN
Returns all rows from the left table and the matching rows from the right table.
If no match, the result from the right table is NULL.
🔹 Types of Triggers
Triggers can be classified based on when and how they are executed:
1. BEFORE Trigger
Executes before the triggering event (INSERT, UPDATE, DELETE) occurs.
Used to validate or modify data before it is inserted or updated in the table.
Q22) State BCNF. How does it differ from 3NF?
Ans: BCNF (Boyce-Codd Normal Form):
A relation (table) is in Boyce-Codd Normal Form (BCNF) if for every functional
dependency (FD) A → B, the determinant A is a super key.
In other words, no non-superkey attribute can determine another attribute.
✅ In short:
BCNF is a stricter version of 3NF.
Every BCNF relation is in 3NF, but not every 3NF relation is in BCNF.
1. Introduction
In databases, indexing is used to speed up data retrieval.
When data grows very large, single-level indexing becomes inefficient because searching
still takes time proportional to the number of index entries.
To solve this, multilevel indexing is used — where multiple levels of indexes are built to
reduce search time.
However, as databases change (insertions, deletions), maintaining these indexes
efficiently requires a dynamic structure — that’s where B+ Trees come in.
5. Structure of B+ Tree
Each internal node contains keys and pointers to child nodes.
Each leaf node contains keys and pointers to actual data records (or to data blocks).
All leaf nodes are linked in a sequential (linked list) manner, allowing efficient
range queries
7. Advantages of B+ Tree (Dynamic Indexing)
1. Balanced structure – search, insert, and delete take O(log n) time.
2. Dynamic growth/shrinking – automatically reorganizes when data changes.
3. Efficient disk access – minimizes I/O by keeping tree height small.
4. Supports range queries easily due to linked leaf nodes.
5. Sequential access – all records can be traversed in sorted order.
8. Operations
Search: Start from root and follow index pointers until reaching the correct leaf node.
Insertion: Insert key in appropriate leaf; if overflow occurs, split nodes and possibly
grow the tree upward.
Deletion: Remove key; if underflow occurs, merge nodes and possibly shrink the
tree.
Q24) Define Multi-valued dependency. Explain the Fourth normal form with an
example.
Ans: Definition: Multi-Valued Dependency (MVD)
A Multi-Valued Dependency (MVD) occurs in a relation when one attribute in a table
uniquely determines another attribute, independently of all other attributes.
It is denoted as:
👉 X →→ Y
This means:
If two tuples (rows) have the same value for attribute X, then they must have the same set
of values for attribute Y, regardless of the values of other attributes.
Q25) Explain in detail about timestamp based concurrency control techniques.
Ans:
1. Introduction
In a multi-user database system, several transactions may execute concurrently. To
maintain data consistency and isolation, we need concurrency control techniques.
Timestamp-Based Concurrency Control (TBCC) is one such technique that uses
timestamps to order transactions in a serializable manner — i.e., as if they were
executed one after another.
2. Basic Idea
Each transaction is assigned a unique timestamp (TS) when it starts.
This timestamp determines the serialization order —
If TS(T1) < TS(T2), then T1 should appear to execute before T2 in the schedule.
3. Timestamp Assignment
A timestamp can be generated in two ways:
1. System Clock: The current time when the transaction starts.
2. Logical Counter: A simple counter incremented for every new transaction.
Transactions:
T1 (TS=25) → read(X) → Allowed (since 25 > WTS(X)=20)
Update RTS(X)=25.
T2 (TS=15) → write(X) → Rejected (since 15 < RTS(X)=25).
→ T2 must be rolled back.
Thus, the order based on timestamps is maintained.
7. Advantages
✅ No Deadlocks:
No waiting — transactions are rolled back instead of waiting, so deadlocks never occur.
✅ Ensures Serializability:
Transactions appear in the order of their timestamps.
✅ Simple to Implement:
Only timestamp comparisons are required.
8. Disadvantages
❌ Starvation:
A transaction may be rolled back repeatedly if its timestamp is small.
❌ More Rollbacks:
Frequent rollbacks may occur under heavy concurrency.
❌ Storage Overhead:
Maintaining RTS and WTS for each data item increases storage needs.
9. Variants
1. Basic Timestamp Ordering (BTO):
o Simple version as explained above.
2. Strict Timestamp Ordering (STO):
o Writes are delayed until the transaction commits → ensures recoverability.
3. Multiversion Timestamp Ordering (MVTO):
o Keeps multiple versions of each data item, allowing more concurrency.
Q26) Explain ACID properties of a transaction.
Ans: n DBMS (Database Management System), every transaction must satisfy certain
properties to ensure data integrity, consistency, and reliability — even in case of
system failures.
These are called ACID properties, where ACID stands for:
1. Atomicity
Meaning: A transaction is treated as a single, indivisible unit of work — it either
completes fully or not at all.
If any part fails, the entire transaction is rolled back.
Example:
Suppose you transfer ₹1000 from Account A to Account B.
o Step 1: Deduct ₹1000 from A.
o Step 2: Add ₹1000 to B.
If the system fails after Step 1 but before Step 2, the entire transaction must be
undone, ensuring no money is lost.
2. Consistency
Meaning: A transaction must bring the database from one valid state to another
valid state.
It should maintain all database rules, constraints, and relationships.
Example:
If total bank balance before transaction = ₹5000,
it should remain ₹5000 after the transfer (even if amounts move between accounts).
3. Isolation
Meaning: Each transaction should execute independently of other transactions.
The intermediate results of a transaction must not be visible to other transactions until
it is committed.
Example:
If two people transfer money at the same time, their operations shouldn’t interfere or
read incomplete results from each other.
4. Durability
Meaning: Once a transaction is committed, its results are permanent in the
database, even if the system crashes afterward.
Example:
After money is successfully transferred and the transaction is committed, the change
remains in the database even if there is a power failure immediately after.
Q27) Explain how Concurrency control can be achieved with locking methods?
Ans: ChatGPT said:
Concurrency Control Using Locking Methods
Concurrency control ensures that multiple transactions can occur simultaneously in a
database without causing inconsistencies. One of the most common techniques to
achieve this is locking.
🔹 What is Locking?
A lock is a mechanism used to control concurrent access to a data item.
When a transaction places a lock on a data item, it restricts other transactions from
accessing that item in a conflicting way until the lock is released.
🔹 Types of Locks
1. Shared Lock (S-lock)
o Placed when a transaction wants to read a data item.
o Multiple transactions can hold shared locks on the same data item
simultaneously.
o No transaction can modify the data while shared locks exist.
Example:
o T1 and T2 can both read item A with shared locks.
2. Exclusive Lock (X-lock)
o Placed when a transaction wants to write (update) a data item.
o No other transaction can read or write the data item until the lock is released.
Example:
o If T1 holds an exclusive lock on A, no other transaction can access A until T1
releases the lock.
🔹 Two-Phase Locking Protocol (2PL)
🔹 Conclusion
Concurrency control using locking methods ensures that:
Database integrity and consistency are maintained.
Transactions appear to execute serially (serializability).
Issues like lost updates, dirty reads, and uncommitted data are prevented.
In short:
Locking-based concurrency control uses shared and exclusive locks, often governed by
the Two-Phase Locking protocol, to synchronize concurrent transactions and maintain
data consistency.
Q28) Explain the difference between two-tier and three-tier architectures. Which is better
suited for Web applications? Why?
Ans:
✅ Conclusion:
Three-tier architecture is preferred for web-based systems because it offers better
scalability, security, and maintainability compared to the simpler two-tier model.
Q29) Define ordered indices. Differentiate between Dense and Sparse indices with
suitable example.
Ans: ChatGPT said:
Ordered Indices – Definition
An ordered index (also called a sequential index) is an index file where the search key
values are stored in sorted (ascending or descending) order. Each entry in the index
contains a key value and a pointer (address) to the corresponding record(s) in the data
file.
👉 Purpose: Ordered indices help in fast searching, sequential access, and efficient range
queries.
👉 Example: If the data file stores student records ordered by Roll_No, an ordered index
on Roll_No allows direct and fast access to records based on roll numbers.
1. Dense Index
In a dense index, there is an index entry for every record in the data file.
Each index entry contains a key value and a pointer to the actual record in the file.
Characteristics:
Faster to search since every key has an index entry.
Requires more storage space.
Index file is large
2. Sparse Index
In a sparse index, index entries exist only for some records — typically the first
record of each block in the data file.
To locate a record, we find the nearest smaller key in the index, then search
sequentially in the data block.
Characteristics:
Requires less space.
Slightly slower than dense index.
Efficient for large files that are stored sequentially.
✅ Summary:
Dense Index → Entry for every record → Fast access, more space.
Sparse Index → Entry for some records → Less space, slower lookup.
1. Data Abstraction
Definition:
Data abstraction in DBMS is the process of hiding the complex details of data storage
and maintenance and showing only the necessary information to the user. It simplifies
database interaction by dividing data representation into different levels.
Levels of Data Abstraction
There are three levels of data abstraction in DBMS:
1. Physical Level (Lowest Level)
o Describes how the data is actually stored in the database.
o It deals with data storage structures, file organization, and access methods.
o Example:
How a record is stored using hashing or indexing, or how pointers are used to
access records.
Example:
Data stored in blocks, indexes, and pointers on the disk.
2. Logical Level (Middle Level)
o Describes what data is stored in the database and the relationships among
the data.
o It hides physical storage details from users.
o Example:
A table "Student" with fields: (Roll_no, Name, Course, Marks)
Example:
STUDENT (Roll_no, Name, Course, Marks)
[Link] Level (Highest Level)
Describes only part of the entire database that a user needs to see.
Different users can have different views of the same database.
It provides security by restricting access to certain data.
Example:
A teacher’s view may show only (Name, Marks), while the admin’s view may show
all fields.
Advantages:
[Link] Model
Data is represented by graphs with many-to-many relationships.
Uses pointers and sets to show relationships.
Example:
A student can enroll in multiple courses, and each course can have multiple students.
Advantages:
Flexible relationships.
Disadvantages:
Complex to design and maintain.
3. Relational Model
Data is stored in tables (relations) with rows and columns.
Each row represents a record (tuple), and each column represents a field (attribute).
Uses keys to link tables.
2. Data Sharing
File System: Data is isolated in separate files, making sharing difficult.
DBMS: Multiple users and applications can share the same data concurrently.
3. Data Integrity
File System: No mechanism to enforce data rules and constraints.
DBMS: Integrity constraints (like primary key, foreign key, etc.) ensure correctness
and accuracy of data.
4. Data Security
File System: Security is handled by the operating system, which is limited.
DBMS: Provides strong security features like user authentication, access control, and
privilege management.
5. Data Independence
File System: Any change in file structure requires changes in application programs.
DBMS: Data is independent of application programs due to data abstraction and
schema levels (physical, logical, and view).
8. Concurrency Control
File System: Multiple users accessing data simultaneously may cause inconsistency.
DBMS: Manages concurrent access using transaction control techniques (like locking
and timestamp).
RAID Techniques
RAID achieves performance and reliability through the following methods:
1. Disk Mirroring (Duplication): Copying the same data on two or more disks.
2. Disk Striping (Splitting): Breaking data into blocks and spreading it across multiple
disks.
3. Parity: Storing error-checking information to recover data in case of disk failure.
Advantages of RAID
Improved performance (especially read/write speed).
High data reliability through redundancy.
Fault tolerance — data can be recovered even if one disk fails.
Increased storage capacity by combining disks.
Disadvantages of RAID
High cost (especially RAID 1, 10 due to redundancy).
Complexity in setup and management.
Parity calculation overhead in some levels (like RAID 5, 6).
Summary
RAID provides a balance between:
Performance
Reliability
Cost
Different RAID levels are used depending on the application needs —
for example:
RAID 0 → For speed (gaming, graphics workstations).
RAID 1 → For reliability (servers).
RAID 5/6 → For enterprise databases and file servers.
Q36) Explain normalization with different normal forms with suitable example.
Ans: Normalization is a process of organizing data in a database to reduce
redundancy (repetition of data) and improve data integrity.
It divides large tables into smaller ones and defines relationships among them.
🔹 Objectives of Normalization
1. To eliminate data redundancy.
2. To ensure data dependencies are logical.
3. To simplify data maintenance.
4. To make the database more efficient.
Different Normal Forms
1️⃣ First Normal Form (1NF)
A relation is in 1NF if:
Each cell contains only atomic (indivisible) values.
Each record is unique (has a unique key).
2️⃣ Second Normal Form (2NF)
A relation is in 2NF if:
It is already in 1NF, and
All non-key attributes are fully functionally dependent on the primary key (no
partial dependency).
Partial dependency means a non-key attribute depends only on part of a composite
key.
3️⃣ Third Normal Form (3NF)
A relation is in 3NF if:
It is already in 2NF, and
There is no transitive dependency (non-key attributes should not depend on other
non-key attributes).
1. Backup System:
A backup is a copy of the database that can be used to restore data in case of failure.
It ensures data availability, integrity, and durability.
Types of Backups:
Full Backup: A complete copy of the entire database.
Incremental Backup: Copies only the data that has changed since the last backup.
Differential Backup: Copies all data changed since the last full backup.
2. Recovery System:
Recovery is the process of restoring the database to a correct state after a failure.
Types of Failures:
Transaction failure: Due to logical errors or system crash during a transaction.
System crash: Loss of data in volatile memory (RAM).
Disk failure: Physical damage or corruption of storage.
Recovery Techniques:
Log-based recovery: Uses transaction logs to redo or undo operations.
Checkpointing: Saves the current state of the database periodically to speed up
recovery.
Shadow paging: Maintains two copies of data pages—one current and one shadow—
to ensure consistency.
Conclusion:
Backup and recovery systems are vital to maintain data reliability, consistency, and
business continuity in case of unexpected failures.
1. Data Abstraction
DBMS provides different levels of data abstraction:
Physical level: How data is stored.
Logical level: What data is stored and relationships among data.
View level: How data is viewed by users.
2. Data Independence
Changes in storage structure or physical schema do not affect the logical structure of
the database or application programs.
It allows flexibility and easier maintenance.
3. Data Consistency
DBMS ensures data accuracy and consistency through integrity constraints.
Reduces data redundancy by using a centralized database.
4. Data Security
DBMS provides controlled access through authentication and authorization.
Only authorized users can access or modify specific parts of the database.
5. Data Integrity
Maintains correctness of data using rules such as primary key, foreign key, and
unique constraints.
9. Data Relationships
Data is stored in the form of tables (relations) and relationships can be defined using
keys and foreign keys
In Short:
A DBMS ensures efficient, consistent, secure, and reliable management of data by
providing features like data independence, abstraction, integrity, and controlled
access.
Q41) Illustrate about integrity and key constraints with suitable examples?
ANS: Integrity and Key Constraints in DBMS
Integrity constraints are rules that ensure the accuracy, consistency, and validity of
data in a database. These constraints restrict the type of data that can be stored in a
table to maintain data correctness.
1. Integrity Constraints
Integrity constraints are broadly divided into three types:
a) Domain Integrity
Ensures that the values in a column are within a specific domain (data type or range).
Example:
c) Referential Integrity
Ensures that the relationship between two tables remains consistent.
Enforced using Foreign Key constraints.
Example:
Q42) Explain the importance of Null values in Relational Model.
ANS: Importance of NULL Values in Relational Model
In the Relational Model, a NULL value represents missing, unknown, or
inapplicable information in a database table. It is not the same as zero (0) or an
empty string (‘ ’); rather, it indicates that the actual value is not available or
undefined.
✅ In short:
NULL values are essential in the relational model because they allow databases to
represent incomplete or inapplicable information realistically while maintaining data
integrity and flexibility.
Q43) Explain in detail, the form of a basic SQL query with a suitable
example.
ANS: Form of a Basic SQL Query
A SQL query is used to retrieve specific data from one or more tables in a database.
The basic form (syntax) of an SQL SELECT query is as follows:
Explanation of the Example
SELECT Department, AVG(Salary) → Retrieves department name and average
salary.
FROM Employee → Data is fetched from the Employee table.
WHERE Salary > 40000 → Only considers employees earning more than ₹40,000.
GROUP BY Department → Groups data by department.
HAVING AVG(Salary) > 45000 → Displays only departments with an average
salary above ₹45,000.
ORDER BY Avg_Salary DESC → Sorts the results by average salary in descending
order.
✅ In short:
A basic SQL query follows a structured format that allows filtering, grouping, and
sorting of data efficiently to extract meaningful information from databases.
Q44) List out various SET comparison operator in SQL and also write about
its use in writing SQL queries.
1. Concept of Hashing
Hashing is a process that converts a search key (K) into a hash address (h(K)) using a hash
function.
This hash address indicates the location (index) in the hash table where the record is stored.
👉 Formula:
h( K)=K mod m
Where:
K = search key value
m = size of hash table
h( K) = hash address
2. Structure of Hash Table
A hash table consists of:
Buckets or Slots: Locations where data records are stored.
Hash Function: Used to compute the index for storing or searching.
Collision Resolution Mechanism: Used when two keys hash to the same address.
a) Open Addressing
All records are stored in the same hash table.
When a collision occurs, the system searches for the next empty slot according to a probing
sequence.
Types of Open Addressing:
1. Linear Probing:
o If a collision occurs at position h(K), try (h(K) + 1), (h(K) + 2), … until an
empty slot is found.
o Problem: Causes Primary Clustering (long blocks of filled slots).
Example:
Table size = 10, keys = 25, 35, 45
h( K)=K mod 10
All map to 5 → stored at 5, 6, 7 respectively.
2. Quadratic Probing:
o Avoids clustering by using quadratic increments:
2
hi (K )=(h( K)+i )mod m
o Tries positions: h( K) , h( K )+12 ,h (K )+2 2 , h( K )+32 ,.. .
3. Double Hashing:
o Uses a second hash function to determine the probe step size.
hi (K )=(h1 (K )+i× h2 (K ))mod m
o Reduces clustering further and improves performance.
7. Limitations
Collisions reduce performance.
Inefficient if load factor (ratio of entries to table size) is high.
Requires good hash function to avoid clustering.
8. Applications
Symbol tables in compilers.
Caching systems.
Database index structures (in-memory).
Search engines and hash-based data structures (like Python dictionaries, Java
HashMaps).
✅ In summary:
Internal hashing stores records in main memory using a hash function to compute storage
addresses. Efficient collision resolution (linear, quadratic, double hashing, or chaining)
ensures quick access and minimal search time.
1. Cluster Index
Definition:
A Clustered Index determines the physical order of data in a table. In other words, the data
rows in the table are stored in the same order as the index. Therefore, there can be only one
clustered index per table, because data rows themselves can only be stored in one order.
Key Features:
The table’s data is physically arranged based on the index key.
The leaf nodes of the index tree contain the actual data rows.
Improves performance for range queries (e.g., BETWEEN, <, >, etc.).
Only one clustered index per table, but multiple non-clustered indexes can exist.
Advantages:
1. Faster data retrieval for range-based queries.
2. Efficient sorting as data is already ordered.
3. Improves I/O performance since related records are stored close together.
Disadvantages:
1. Slower insert/update operations, since maintaining order requires rearranging rows.
2. Only one clustered index per table.
3. Rebuilding the clustered index can be time-consuming for large datasets.
2. Multilevel Index
Definition:
A Multilevel Index is an indexing method where indexes are built on top of other indexes
to reduce the number of disk accesses required for searching.
It is a hierarchical indexing structure—similar to a tree (like B-tree or B+ tree).
Need for Multilevel Indexing:
If a file is large, the primary index itself may not fit in memory.
So, we create a second-level index on the first-level index.
If needed, we can continue creating higher levels until the top-level index fits entirely in main
memory.
E
xample:
Suppose we have 1,000,000 records and use a primary index with 1000 entries per block.
Level 1 index: 1,000,000 / 1000 = 1000 entries
If each block can store 100 entries, we need 10 blocks for level 1 index.
So, we build a Level 2 index (of 10 entries) to locate the Level 1 index blocks.
Thus, the search process reduces from thousands of block reads to just a few levels of index
traversal.
Advantages:
1. Efficient searching: Reduces disk I/O by limiting search path.
2. Scalable: Works well for very large databases.
3. Memory optimization: Higher levels can fit into main memory.
Disadvantages:
1. Complexity: Managing multiple levels increases maintenance overhead.
2. Update cost: Insertion or deletion may require updates at multiple levels.
3. Storage overhead: Additional storage is needed for multiple index levels.
✅ In summary:
A Clustered Index organizes actual data based on the index key.
A Multilevel Index is a hierarchical index structure that improves access speed for
large datasets.
2. Data Sharing
o Multiple users and applications can access the same data concurrently without
conflicts.
o This supports multi-user environments and collaboration.
Example: In a university database, both the administration and students can access course
information simultaneously.
4. Data Security
o Protects data from unauthorized access through authentication, authorization,
and encryption.
o Different users can have different access privileges.
Example: A student can view grades, but only a teacher can update them.
5. Data Independence
o The structure of the database can be changed without affecting how
applications access data.
o Separates the logical view of data from the physical storage details.
Example: Changing how data is stored on disk without affecting SQL queries.
Conclusion
A Database Management System (DBMS) serves as an organized framework for handling
data efficiently.
It ensures that data is accurate, secure, consistent, and easily accessible, making it an
essential component of modern information systems.
In short:
The purpose of a database system is to provide a systematic, secure, and efficient way to
store, manage, and retrieve data while ensuring data integrity, consistency, and accessibility
for multiple users.
🔹 Example
Suppose a database has student records.
Physical Level: Data stored as binary records in hard disk files.
Logical Level: STUDENT(RollNo, Name, Course, Age)
View Level:
o Student view: shows Name, Course
o Admin view: shows all attributes.
✅ In Summary
Data Abstraction = Hiding data storage details → showing only relevant
information.
It provides simplicity, security, and data independence in a database system.
1. Data Storage
Data storage refers to how data is physically stored and managed in a database system.
a) Storage Hierarchy
Data in a database is stored across several layers of memory:
Primary Storage: Main memory (RAM) – used for temporary data while processing
queries.
Secondary Storage: Hard disks or SSDs – used for permanent storage of database
files.
Tertiary Storage: Backup devices like tapes or cloud storage – used for archival and
recovery.
b) Storage Structures
DBMS uses various file structures to manage data efficiently:
Heap Files: Records are stored in no particular order.
Sequential Files: Records are stored in sorted order (based on key field).
Indexed Files: Uses indexes (like B+ trees, hash indexes) for fast retrieval.
Clustered Files: Related records are stored together physically for faster access.
c) Data Storage Formats
Data is stored in:
Tables (Relations): Rows and columns structure.
Pages/Blocks: Each table is divided into fixed-size blocks stored on disk.
Records and Fields: Each block contains records (tuples) with multiple fields
(attributes).
2. Querying
Querying is the process of retrieving or manipulating data stored in the database using a
query language, typically SQL (Structured Query Language).
a) Types of Queries
Data Retrieval: Using SELECT statements to extract data.
Data Modification: Using INSERT, UPDATE, DELETE commands.
Schema Definition: Using CREATE and ALTER to define database structure.
b) Query Processing Steps
1. Parsing: The DBMS checks query syntax and semantics.
2. Optimization: The query optimizer finds the most efficient way to execute the query
(chooses indexes, joins, etc.).
3. Execution: The optimized query plan is executed to retrieve results from stored data.
d) Query Optimization
The DBMS uses indexes, joins, and access paths to minimize I/O operations and improve
speed.
In short:
👉 Data Storage ensures data is efficiently saved and organized.
👉 Querying allows users to extract and manipulate that data effectively through SQL
commands.
2. FUNCTION
A Function is similar to a procedure but it must return a single value.
It is often used in SQL expressions (like SELECT statements).
✅ Summary:
Function: returns a value and can be used in queries.
Procedure: performs operations and may not return a value.
🔹 Definition:
A schedule (sequence of read/write operations from multiple transactions) is said to
be serializable if its outcome is the same as that of some serial schedule — i.e., a
schedule where transactions are executed one after the other without overlapping.
🔹 Types of Serializability:
There are mainly two types:
1. Conflict Serializability
A schedule is conflict serializable if it can be transformed into a serial schedule by
swapping non-conflicting operations.
Two operations conflict if:
They belong to different transactions, and
They operate on the same data item, and
At least one of them is a write operation.
Example:
Schedule Explanation
T1: Read(A), Both access the same data item A; order of writes
Write(A) matters.
T2: Read(A),
Schedule Explanation
Write(A)
If we can reorder operations of T1 and T2 without changing the result, it is conflict
serializable.
2. View Serializability
A schedule is view serializable if it is view equivalent to a serial schedule —
meaning:
Each transaction reads the same values as in the serial schedule, and
The final writes on each data item are the same.
Note:
All conflict-serializable schedules are view-serializable,
but not all view-serializable schedules are conflict-serializable.
Here,
T1 holds X and waits for Y (locked by T2),
T2 holds Y and waits for X (locked by T1).
Both transactions wait forever — this is a deadlock.
In short:
Deadlock handling ensures that transactions do not get stuck waiting forever for
resources.
It can be achieved through prevention, avoidance, or detection & recovery
techniques depending on the DBMS strategy.
Q52) Why would you choose a database system instead of simple storing data in
file processing system? Compare file processing system and DBMS.
ANS: A Database Management System (DBMS) is preferred over a File Processing
System (FPS) because it offers better data management, security, consistency, and
efficiency.
Let’s understand the reasons and comparison clearly 👇
✅ Conclusion
A DBMS is preferred because it provides:
Centralized control of data,
Better data integrity, security, and consistency,
Easier data access and management using SQL,
Support for multiple users and recovery features.
Hence, for large-scale, multi-user, and secure data management — DBMS is the best
choice.
a) Query Processor
The Query Processor is the component of a DBMS responsible for interpreting and
executing user queries.
It transforms high-level queries (like SQL) into a low-level execution plan that the
database can perform efficiently.
Components of Query Processor:
1. DDL Interpreter
o Interprets the Data Definition Language (DDL) statements such as CREATE,
ALTER, and DROP.
o Passes the schema definitions to the Metadata Manager.
2. DML Compiler
o Translates Data Manipulation Language (DML) statements (like SELECT,
INSERT, UPDATE, DELETE) into a query execution plan.
o Breaks down complex queries into a series of low-level operations.
3. Query Optimizer
o Finds the most efficient way to execute a query by considering different query
plans.
o Uses optimization techniques to minimize cost (time, CPU, I/O).
o Example: Choosing the best index or join method.
4. Query Evaluator / Executor
o Executes the optimized query plan.
o Interacts with the storage manager to retrieve or modify data.
o Returns the results to the user or application.
Applications of DBMS:
1. Banking Systems:
Used for managing customer accounts, transactions, and loans.
2. Airline Reservation Systems:
Used for booking, scheduling, and tracking flight information.
3. Hospital Management Systems:
Used for maintaining patient records, doctor schedules, and billing information.
✅ In short:
DBMS is a system that manages data efficiently and provides features like data
security, consistency, and recovery — making it essential for modern data-driven
applications.