Bank Application Database Design Guide
Bank Application Database Design Guide
Bank, we need to first define entities, attributes, relationships, and constraints. Below is a
complete breakdown, including an E-R diagram description.
Assumptions
6. A Loan can be taken by one or more customers, and a customer can take multiple
loans.
8. Each customer has a unique Customer ID, and each account has a unique Account
Number.
1. Customer
• Customer_ID (PK)
• Name
• Date_of_Birth
• Gender
• Address
• Phone
• PAN_Number
• Aadhar_Number
2. Bank
• Bank_ID (PK)
• Bank_Name
• Head_Office_Address
3. Branch
• Branch_ID (PK)
• Branch_Name
• IFSC_Code
• Address
• Bank_ID (FK)
4. Account
• Account_Number (PK)
• Account_Type
• Balance
• Date_Opened
• Customer_ID (FK)
• Branch_ID (FK)
5. Transaction
• Transaction_ID (PK)
• Account_Number (FK)
• Transaction_Date
• Transaction_Type (Credit/Debit)
• Amount
• Description
6. Loan
• Loan_ID (PK)
• Amount
• Interest_Rate
• Loan_Type
• Branch_ID (FK)
• Customer_ID (FK)
• Loan_ID (FK)
• Disbursal_Date
2. Branch — Account
3. Customer — Account
4. Account — Transaction
5. Branch — Loan
o Many-to-Many relationship
(iii) Constraints
2. Foreign Keys:
o Account.Customer_ID → Customer.Customer_ID
o Account.Branch_ID → Branch.Branch_ID
o Branch.Bank_ID → Bank.Bank_ID
o Transaction.Account_Number → Account.Account_Number
o Loan.Branch_ID → Branch.Branch_ID
o Customer_Loan.Customer_ID → Customer.Customer_ID
o Customer_Loan.Loan_ID → Loan.Loan_ID
3. Balance ≥ 0 in Account
| |
| v
v Transaction
Entities: Boxes
Relationships:
Types of Serializability:
• View Serializability: Based on final read/write results (more general, but harder to
check).
We will focus on conflict serializability, which is commonly asked and easier to test.
Schedule A:
Operation T1 T2
Step 1 Read(X)
Operation T1 T2
Step 2 Read(X)
Step 3 Write(Y)
Step 4 Write(Y)
Step 5 Commit
Step 6 Commit
Conflict Rules:
2. T1: Read(X) and T2: Read(X) → no conflict (both reads are safe)
• Nodes: T1, T2
In our case:
Final Answer:
Table Structures
• Sample Data
• Student table
• Programme table
Name
Ayesha
Charan
•
• (ii) List all the programmes in the increasing order of programme
fee:
• SELECT *
• FROM Programme
• ORDER BY fee ASC;
• Result:
total_programmes
3
•
• (iv) List st_id, name, prof_name for all the students:
• SELECT s.st_id, [Link], p.Prof_name
• FROM Student s
• JOIN Programme p ON s.programme_code = p.programme_code;
• Explanation of Join:
• We’re using an INNER JOIN to combine students with the programme they are
enrolled in using the programme_code.
• Result:
1. Transaction Failures
These failures occur within the transaction itself, due to logical or runtime errors. The DBMS
aborts and rolls back the transaction.
Causes:
• User-initiated aborts
• Deadlock detection
Example: A transaction tries to withdraw more money than available in the account →
Constraint fails → Transaction aborted.
2. System (or Software) Failures
These failures occur when the operating system, DBMS software, or the system process
crashes. In such cases, RAM contents are lost, but the disk is intact.
Causes:
• OS crash
Effect: All active transactions are lost from memory and must be recovered using logs.
These are hardware failures where the disk itself is damaged, resulting in loss of data stored
in the database.
Causes:
Effect: The DBMS cannot access the database at all; recovery must be done from backups and
logs.
4. Communication Failures
These occur in distributed database systems, where transactions span multiple nodes.
Causes:
• Network disconnection
• Message loss
5. Concurrency-Related Failures
These happen when multiple transactions interfere with each other inappropriately, despite
locking and isolation controls.
Causes:
• Deadlocks (two transactions waiting on each other)
Example: Two transactions update the same row simultaneously, violating consistency.
In Simple Words:
• Data Integrity = Keep data correct and consistent, even after updates or errors.
A Data Warehouse (DW) is a system used for storing, analyzing, and reporting large volumes
of historical data collected from different sources. It supports decision-making by transforming
raw data into meaningful information.
1. Data Sources
• Internal systems: OLTP databases, CRM, ERP
5. Metadata
7. Data Marts
+----------------------+
| Staging Area |
+----------------------+
+----------------------+
| Data Warehouse |
| (Central Repository)|
+----------------------+
+----------------+---------------+------------------+
| | |
| |
+----------------+
+-------------------+
| End-User Tools |
+-------------------+
Definition: Union includes all unique tuples from both relations (no duplicates).
Assumption: Both relations are union-compatible (same attributes and types).
Result: P ∪ Q
Pid Pname
001 abc
012 xyz
014 lmn
015 opq
016 sss
017 ssd
Schema of Result:
+------------+-----------+-----------+
+------------+-----------+-----------+
| 1001 | Aditi | 85 |
| 1002 | Bharat | 78 |
| 1003 | Charu | 92 |
| 1004 | Deepak | 88 |
| 1005 | Esha | 81 |
+------------+-----------+-----------+
• New data must be inserted in the correct order (might involve rewriting).
Advantage Explanation
Efficient for Sequential Best suited for applications that process all records (e.g.,
Access payroll, billing).
Disadvantage Explanation
Use Cases
• Payroll processing
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Definition:
• Each column contains only one value per row (no repeating groups or arrays).
Definition:
Here, Student_Name depends only on Roll_No, not the full key (Roll_No, Subject) ⇒ Partial
dependency ⇒ Not in 2NF
Convert to 2NF:
Student Table:
Roll_No Student_Name
101 Amit
Roll_No Student_Name
102 Rekha
Marks Table:
101 Math 80
101 Science 75
102 English 85
Now all non-key attributes are fully dependent on the entire primary key.
Definition:
1. It is in 2NF, and
1 Ravi D01 HR
2 Sita D02 IT
Here:
Convert to 3NF:
Employee Table:
1 Ravi D01
Emp_ID Emp_Name Dept_ID
2 Sita D02
Department Table:
Dept_ID Dept_Name
D01 HR
D02 IT
Now, each non-prime attribute depends only on the key, no transitive dependencies.
• Lost updates
• Dirty reads
• Inconsistent reads
• Data consistency
1. Binary Locks
Transaction Operation Lock Type Can Others Read? Can Others Write?
Definition:
1. Growing Phase:
o No release is allowed.
2. Shrinking Phase:
Time →
+-------------------+-------------------+
+-------------------+-------------------+
Example Timeline:
T1: Lock(X)
T1: Lock(Y)
T1: Unlock(X)
T1: Unlock(Y)
The transaction must not acquire any new locks after it starts releasing.
Example of 2PL:
Transaction T1:
2. Lock(Y)
3. Read(X)
4. Write(Y)
6. Unlock(Y)
Advantages of 2PL
• Guarantees conflict-serializability
Disadvantages of 2PL
• Can cause deadlocks (e.g., two transactions waiting on each other's locks)
Reason Explanation
Improved Multiple users can work simultaneously → better CPU &
Performance resource utilization.
Better Throughput More transactions completed per unit time.
Minimized Waiting
Users don't need to wait for others to finish.
Time
Reason Explanation
Efficient Resource Disk I/O, memory, and processor can be used by multiple users
Use concurrently.
•
• Problems with Concurrent Transactions
• Without proper control (like locking or scheduling), concurrent transactions may lead
to inconsistencies. Let’s explore the key issues:
•
• 1. Lost Update Problem
• Occurs When: Two transactions read the same data and update it, but one update
is overwritten by the other.
• Example:
• Initial value of X = 100
• T1:
• Read X (100)
• X = X + 50 → 150
• Write X
• T2:
• Read X (100)
• X = X - 30 → 70
• Write X
• Final Value = 70, but should be 120
Problem: T1’s update was lost.
•
• 2. Dirty Read Problem (Uncommitted Dependency)
• Occurs When: One transaction reads data modified by another uncommitted
transaction.
• Example:
• T1:
• Update X = 500
• T2:
• Rollback → X = original
• Problem: T2 used a dirty (invalid) value.
•
• 3. Inconsistent Read (Non-repeatable Read)
• Occurs When: A transaction reads the same data twice and gets different values
because another transaction updated it in between.
• Example:
• T1:
• Read X → 200
• ... (some time passes)
• Read X again → 300
• T2 (in between):
• Update X = 300
• Commit
• Problem: T1 sees inconsistent data.
•
• 4. Phantom Read
• Occurs When: A transaction reads a set of rows, and another transaction
inserts/deletes rows that would have matched the read criteria.
• Example:
• T1:
Relational databases (RDBMS) are powerful for structured, tabular data. However, they have
limitations when handling complex, interrelated, and multimedia data (e.g., CAD/CAM,
scientific data, multimedia, etc.).
Poor support for complex data Supports complex/recursive data types (arrays, structs, etc.)
Object-relational systems allow you to define and use user-defined data types such as:
• Arrays/lists
Example:
street VARCHAR,
city VARCHAR,
zip INT
);
id INT,
name VARCHAR,
address AddressType
);
2. Inheritance
Like in OOP, one type (or table) can inherit attributes and methods from another.
Example:
name VARCHAR,
age INT
) NOT FINAL;
course VARCHAR
);
Advantage:
• Multiple references can point to the same object (even if no common value)
Example:
dept_id INT,
dept_name VARCHAR
);
emp_id INT,
emp_name VARCHAR,
);
Definition:
101 Aditi CS
102 Rahul IT
103 Aditi CS
In this table:
But:
• Name → Roll_No is not valid, because two students can have the same name.
Type Description
Real-Life Example
1 Ravi D01 HR
2 Sita D02 IT
Here:
Strong Entity:
Example:
Weak Entity:
Example:
Multivalued Attribute:
Example:
Dependency:
Example:
Roll_No → Name
Definition:
• Tables
• Columns
• Data types
• Constraints
• Relationships
Types:
Uses:
Definition:
Query processing is the series of steps taken by a DBMS to execute a SQL query efficiently.
3. Optimization: Choose the best execution plan (using indexes, join orders, etc.).
Goal:
• Ensure correctness
• Here is a comparison between the traditional file-based system and the database
approach, highlighting their key differences and similarities:
•
• 1. Definition
However, for decomposition to be useful and valid, it must satisfy three key desirable
properties:
1. Lossless-Join Decomposition
Definition:
A decomposition is lossless if the original relation can be exactly reconstructed by joining the
decomposed relations.
Example:
Consider a relation:
R(EmployeeID, Name, Department, DepartmentLocation)
• R2(Department, DepartmentLocation)
2. Dependency Preservation
Definition:
A decomposition is dependency-preserving if all functional dependencies (FDs) from the
original relation can still be enforced without having to join the decomposed relations.
Example:
Original relation:
R(StudentID, CourseID, Instructor)
FDs:
Decompose into:
• R1(StudentID, CourseID)
• R2(CourseID, Instructor)
Now the original dependency StudentID, CourseID → Instructor is not preserved, because it
spans both R1 and R2.
This decomposition is not dependency-preserving.
Definition:
Decomposition should eliminate redundancy, which helps avoid:
• Insertion anomaly
• Update anomaly
• Deletion anomaly
Example:
Original relation:
R(StudentID, StudentName, Department, DepartmentLocation)
If Department and DepartmentLocation are repeated for many students, this creates
redundancy.
Decompose into:
• R2(Department, DepartmentLocation)
Now each department and its location are stored only once, avoiding redundancy and
anomalies.
Query processing is the series of steps a Database Management System (DBMS) follows to
interpret, optimize, and execute a query (usually written in SQL) to retrieve or manipulate data
efficiently.
In simpler terms, it is how the DBMS translates a user's SQL query into low-level operations
that access the physical data stored in the database.
Step
Step Name Description
No.
Example:
SQL Query:
Steps involved:
1. Parsing: Check SQL syntax and identify tokens (SELECT, FROM, WHERE, etc.).
Summary Diagram:
SQL Query
[2] Optimization
↓
[3] Evaluation Plan Generation
[4] Execution
Result
Relational databases (RDBMS) are widely used, but they have several limitations, especially
when dealing with complex, modern data and applications. Here are the major limitations:
• RDBMSs primarily deal with structured data like numbers, strings, and dates.
• They struggle with multimedia data (images, audio, video), complex objects (CAD files,
maps), and user-defined types.
3. Impedance Mismatch
4. Limited Semantics
• RDBMS is not ideal for storing deeply nested or hierarchical structures, such as XML,
JSON, or social network graphs.
Need for Object-Oriented Databases (OODBMS)
To overcome these limitations, Object-Oriented Databases were developed. They combine the
database capabilities with object-oriented programming principles.
Feature Explanation
5. Closer Integration with Makes it easier to store and retrieve application objects
OOP Languages without mapping them to relational tables.
6. Support for Versioning and Useful for applications like CAD/CAM, where object states
Persistence change over time.
In a Relational DBMS:
To store a Shape object, you may need multiple tables for Circle, Rectangle, etc., and write joins
to retrieve them.
In an Object-Oriented DBMS:
You can have a base class Shape and subclasses like Circle, Rectangle with attributes and
methods stored as-is. No need for joins—objects are stored and retrieved directly.
Purpose:
Retrieves specific rows (tuples) from a relation that satisfy a given condition.
Symbol: σ
Syntax: σ<condition>(Relation)
Example:
Relation: Employee
Result:
Purpose:
Retrieves specific columns (attributes) from a relation.
Symbol: π
Syntax: π<attribute list>(Relation)
Example:
Query: List only the names of employees.
Relational Algebra: πName(Employee)
Result:
Name
Alice
Bob
Raj
Purpose:
Combines all possible pairs of tuples from two relations.
Symbol: ×
Syntax: Relation1 × Relation2
Example:
Employee:
EmpID Name
1 Alice
2 Bob
Department:
DeptID DeptName
D1 HR
D2 IT
Result:
1 Alice D1 HR
1 Alice D2 IT
2 Bob D1 HR
2 Bob D2 IT
Purpose:
Combines related tuples from two relations based on a common attribute.
Symbol: ⨝
Syntax: Relation1 ⨝<condition> Relation2
Example:
Employee:
1 Alice D1
2 Bob D2
Department:
DeptID DeptName
D1 HR
D2 IT
Result:
1 Alice D1 HR
2 Bob D2 IT
Purpose:
Combines distinct tuples from two relations.
Symbol: ∪
Syntax: Relation1 ∪ Relation2
(Requires same schema: same number & type of attributes)
Example:
A:
EmpID Name
101 Alice
102 Bob
B:
EmpID Name
102 Bob
103 Raj
Query: A ∪ B
Result:
EmpID Name
101 Alice
102 Bob
EmpID Name
103 Raj
Purpose:
Returns tuples that are in the first relation but not in the second.
Symbol: −
Syntax: Relation1 − Relation2
Example:
A:
EmpID Name
101 Alice
102 Bob
B:
EmpID Name
102 Bob
103 Raj
Query: A − B
Result:
EmpID Name
101 Alice
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1.1. Patient
• Attributes:
o Name
o Age
o Gender
o Address
o PhoneNumber
o BloodGroup
1.2. Doctor
• Attributes:
o Name
o Specialization
o PhoneNumber
o Email
1.3. Department
• Attributes:
o DeptName
o Location
1.4. Appointment
• Attributes:
o Date
o Time
1.5. Treatment
• Attributes:
o Description
o Date
o Cost
o PatientID (Foreign Key)
1.6. Room
• Attributes:
o RoomType
o ChargesPerDay
o AvailabilityStatus
1.7. Admission
• Attributes:
o AdmissionDate
o DischargeDate
• Relation: A patient can make multiple appointments with doctors, and a doctor can
have multiple appointments with patients.
• Cardinality: Many-to-Many
• Relation: A doctor works in one department, but a department can have many
doctors.
• Relation: A patient can be admitted to a room; a room can be assigned to one patient at
a time.
csharp
CopyEdit
| |
Receives Administers
| |
[Treatment] [Appointment]
[Admission]
4. Constraints
• Foreign Keys:
o [Link] → [Link]
o [Link] → [Link]
o [Link] → [Link]
o [Link] → [Link]
o [Link] → [Link]
o [Link] → [Link]
o [Link] → [Link]
• Room Availability Constraint: Only one active admission per room at a time.
The physical architecture of a Database Management System (DBMS) refers to the internal
working of the DBMS and how data is actually stored, retrieved, and managed on the storage
medium (usually a disk). It focuses on the hardware-level and storage-level components that
support database operations.
+-------------------------+
| Query Processor |
+-------------------------+
+-------------------------+
| Execution Engine |
+-------------------------+
+--------------------+----------------------+
| |
v v
+-------------------------+ +----------------------------+
+-------------------------+ +----------------------------+
| |
v v
+-------------------------+ +----------------------------+
+-------------------------+ +----------------------------+
v
+-------------------------+
| Disk Storage |
+-------------------------+
1. Query Processor
2. Execution Engine
3. Buffer Manager
o Ensures frequently accessed data blocks are kept in memory to reduce disk I/O.
4. Transaction Manager
5. Recovery Manager
6. File Manager
7. Disk Storage
o The physical medium where data, logs, indexes, and metadata are stored.
• 1. INSERT Command
• Used to add new records (rows) into a table.
• Syntax:
• UPDATE table_name
• SET column1 = value1, column2 = value2, ...
• WHERE condition;
• Example:
• UPDATE Students
• SET Age = 22
• WHERE StudentID = 101;
• This updates the age of the student with ID 101 to 22.
•
• 3. DELETE Command
• Used to remove existing records from a table.
• Syntax:
o Best suited for applications where large volumes of data need to be processed in
order (e.g., payroll systems, billing systems).
o Example: Reading all student records in roll number order for exam result
generation.
These are two essential integrity constraints that ensure the accuracy and consistency of
data in a relational database.
Definition:
Entity integrity ensures that every table (relation) must have a primary key, and the primary
key value cannot be NULL.
It ensures that each row (tuple) in a table is uniquely identifiable.
Rule:
Primary key column(s) must have unique and NOT NULL values.
Example:
101 Aman 20
102 Riya 21
Definition:
Referential integrity ensures that a foreign key value must either be NULL or match an
existing primary key value in the referenced table.
It maintains valid references between tables.
Rule:
Example:
Table: Departments
10 HR
20 IT
Table: Employees
1 Amit 10
2 Renu 20
• Value 30 does not exist in the parent table, so it violates referential integrity.
Explanation of Third Normal Form (3NF) and Boyce-Codd Normal Form (BCNF)
Normalization is the process of organizing data to minimize redundancy and dependency. Both
3NF and BCNF aim to achieve a better database design.
Definition:
Example:
• DeptName → HOD
Here:
Department(DeptName, HOD)
1. It is in 3NF, and
In simpler terms: Left side of every functional dependency must be a super key.
Example:
• CourseID → Instructor
• Room → Instructor
Break into:
RoomInstructor(Room, Instructor)
CourseRoom(CourseID, Room)
Now:
Example A non-prime attribute depending on another non- Left side of FD not being a
Violation prime super key
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Indexes in a database are used to speed up the retrieval of data. Without indexes, the
database must perform a full table scan, which is slow for large tables.
Benefits of Indexes:
Types of Indexes:
Definition:
A primary index is built on the primary key of a table. The data is sorted based on the primary
key, and the index stores pointers to data blocks.
Key Points:
Example:
For table:
Student(StudentID, Name, Age)
If StudentID is the primary key, the primary index is created on StudentID.
Definition:
A clustering index is created on a non-primary key column where data is physically stored
together (clustered) based on that column’s values.
Key Points:
• Only one clustering index per table
Example:
For table:
Employee(EmpID, DeptID, Name)
If many queries use DeptID, a clustering index on DeptID makes sense.
All employees from the same department will be stored close together on disk.
Definition:
A secondary index is created on non-primary key columns and does not affect the physical
order of the table.
Key Points:
Example:
For table:
Book(BookID, Title, Author, Price)
If users often search by Author, create a secondary index on Author.
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
A transaction must either complete entirely or have no effect at all — ensuring the
consistency and integrity of the database.
Example of a Transaction:
-- Start Transaction
-- Commit Transaction
If one step fails, the transaction must be rolled back, so neither account is affected.
1. Atomicity
• All or nothing: Either all operations in the transaction are completed, or none.
In the bank example: Deducting ₹1000 from A but failing to credit B would violate atomicity.
2. Consistency
In the bank example: The total amount in the system before and after the transfer remains
the same.
3. Isolation
• Concurrent transactions are executed as if they were run one after the other.
If two users transfer money at the same time, isolation ensures the operations don’t conflict
or corrupt data.
4. Durability
• Once a transaction is committed, its changes are permanently saved, even in case of
a crash.
If power fails after money is transferred and the transaction is committed, the changes
remain in the database.
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Database recovery is the process of restoring the database to a correct state after a failure
such as:
• System crash
• Power failure
• Disk failure
• Transaction failure
The goal is to ensure data consistency, integrity, and reliability by recovering from
incomplete or incorrect transactions.
• Application/software error
When It Happens When an error is detected After restoring data from a backup
Affected Transactions that were active at Transactions that were committed but
Transactions time of crash not yet written to disk
Example Use Power fails during money transfer Power fails after successful transfer →
Case → undo partial update redo the committed update
Example Scenario:
3. T1 commits
• Forward Recovery will redo T1 if it was committed but not flushed to disk
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
A Hash Join is an efficient join algorithm used to perform equi-joins (joins using = condition)
between two large relations (tables), especially when no index is available.
SELECT *
FROM R JOIN S
ON R.A = S.A;
1. Build Phase:
o Choose the smaller relation (say, R) and create an in-memory hash table on
the join attribute (R.A).
2. Probe Phase:
o For each tuple in S, use the same hash function to find matching tuples in the
hash table built from R.
Assumptions:
Total Cost:
Explanation:
• b(R): To read all blocks of relation R into memory and build the hash table
Example:
• Let’s say:
Then:
• Grace Hash Join – used when neither relation fits entirely in memory (uses partitioning).
• Hybrid Hash Join – optimizes memory usage during the build phase.
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Definition:
Multi-list file organization allows records in a file to be linked using more than one field (key).
It supports multiple linked lists, each sorted by a different field.
Features:
Example:
In a student-course file, one list may be maintained by StudentID, and another by CourseID,
allowing fast access by either.
Definition:
A relation is in 2NF if:
Example:
Relation: Enrollment(StudentID, CourseID, CourseName)
If CourseName depends only on CourseID (not the full key), it's a partial dependency, violating
2NF.
Definition:
A schedule is serializable if the outcome is the same as some serial execution of the same
transactions (i.e., one after the other with no interleaving).
Importance:
Types:
Definition:
A data warehouse is a centralized repository that stores large volumes of historical,
integrated, and subject-oriented data for analysis and reporting.
Features:
• Stores data from multiple sources (via ETL: Extract, Transform, Load)
Example:
A retail chain uses a data warehouse to analyze sales across locations over the past 5 years.
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1. Customer
2. Account
3. Transaction
(ii) Attributes of Each Entity
Customer
• Name
• PhoneNumber
• Address
Account
• Balance
Transaction
• Date
• Amount
1. Customer–Account
2. Account–Transaction
|1:M
|1:M
Customer(
Name,
PhoneNumber,
Address
Account(
Balance,
Transaction(
Date,
Type,
Amount,
Primary Keys:
• Customer(CustomerID)
• Account(AccountNumber)
• Transaction(TransactionID)
Foreign Keys:
Other Constraints:
+++++++++++++++++++++++++++++++++++++=======================================
Relations
(i) List the id and name of all students of Programme whose p_code is “MCA”
FROM Student
SELECT *
FROM Programme
FROM Student
GROUP BY p_code;
(iv) List id, name, p_code, title of all students of the programme whose p_code is “CIT”
FROM Student S
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
(i) Transaction
Definition:
A transaction is a sequence of one or more SQL operations (e.g., INSERT, UPDATE, DELETE)
performed as a single logical unit of work.
It must follow the ACID properties — Atomicity, Consistency, Isolation, and Durability.
Example:
BEGIN;
COMMIT;
This is a money transfer between accounts A1 and A2. Either both operations succeed, or
none do.
(ii) Locking
Definition:
Locking is a concurrency control mechanism that prevents multiple users from modifying
the same data simultaneously, to ensure data integrity.
There are two types of locks:
Example:
(iii) Checkpoint
Definition:
A checkpoint is a point in time at which the state of the database is saved to disk.
It reduces the amount of log records that must be reprocessed during recovery.
Example:
(iv) Recovery
Definition:
Recovery is the process of restoring the database to a consistent state after a crash or failure
using logs and backups.
It involves:
Example:
If a transaction was halfway through updating multiple records when power failed, recovery
uses logs to undo partial updates or redo committed ones.
Definition:
Query cost refers to the resources (I/O, CPU, time) required to execute a query.
The query optimizer uses cost estimation to select the most efficient execution plan.
Example:
==========================================+++++++++++++++++++++++++++
Stores data in rows and Stores data as objects, including attributes and
Data Storage
columns methods
Example:
• In RDBMS, a Student and Course are separate tables linked by foreign key.
Discover hidden patterns, trends, Organize and store data for reporting
Purpose
predictions and analysis
Example:
• Data Warehousing: Stores 5 years of sales data from different branches.
• Data Mining: Analyzes that data to predict future customer buying behavior.
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
This typically happens in un-normalized tables (or poorly normalized ones), where the same
piece of information is repeated in multiple rows.
Table: StudentProgramme
What happened?
• The programme name for "MCA" was updated for one student (Ankit) but not for the
others, causing inconsistent data.
Why It Happens
• An update to one row requires updating all duplicates — if not done, inconsistency
arises.
Normalized Design:
Now, if you update the ProgrammeName in just one place (in the Programme table), all linked
students reflect the change.
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Data Independence refers to the ability to modify the schema at one level of a database
system without affecting the schema at the next higher level.
It helps in decoupling how data is stored from how it is used, enabling flexibility and
maintainability in database systems.
• Ability to change the logical schema (like tables, views, relationships) without
changing application programs.
Example:
If you add a new column email to the Student table:
• Ability to change the physical storage (like indexing, file organization) without
affecting the logical schema.
Example:You reorganize the Student table to store data in a different file format or move it to
SSD instead of HDD.
Still, the user queries:
remain unchanged.
Physical Schema
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++==============
In a relational database, keys are used to uniquely identify rows (tuples) in a table. Let's break
down the three main types of keys with definitions and examples.
Definition:
A super key is any combination of attributes that can uniquely identify a row in a table.
Example:
• {StudentID}
• {Email}
• {StudentID, Name}
• {Phone, Name}
A candidate key is a minimal super key — i.e., a super key with no redundant attributes.
• {StudentID}
• {Email}
• {Phone}
(Each is minimal and uniquely identifies a student)
Definition:
A primary key is one of the candidate keys chosen by the database designer to uniquely
identify records.
It must be:
• Unique
• Not NULL
Example:
Then StudentID becomes the official way the DBMS uniquely identifies each row
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Both generalization and specialization are abstraction techniques used in the Entity-
Relationship (E-R) model to manage complexity in database design, especially when dealing
with hierarchies.
(i) Generalization
Definition:
Generalization is the process of combining two or more lower-level entities into a higher-
level (general) entity based on common features.
Example:
Entities:
Vehicle
/ \
Car Bike
(ii) Specialization
Definition:
Example:
Entity:
• Manager(EmpID, DeptManaged)
• Engineer(EmpID, SkillSet)
Here, Employee is the superclass, and Manager and Engineer are subclasses.
Employee
/ \
Manager Engineer
Each subclass inherits all attributes from Employee and adds its own.
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Indexes are used to speed up data retrieval in a database by providing faster access to records.
(i) Primary Index
Definition:
A Primary Index is built on the primary key (or another unique key) of a table.
It is an index on an ordered file where the data is sorted based on the key.
Key Characteristics:
Example:
If data is stored in order of StudentID, a primary index on StudentID would point to the starting
block of each group of StudentIDs.
101 Block 1
104 Block 2
107 Block 3
So if you search for StudentID = 105, the DBMS goes directly to Block 2.
Definition:
Key Characteristics:
• Can be non-unique
Example:
If you create a secondary index on Age, and multiple students have the same age, the index
would look like:
Age Pointers to Records
18 [R1, R3]
This index helps efficiently search all students aged 19, even though the table is not sorted on
Age.
Duplicates
No (on unique fields only) Yes (can be on duplicate values)
Allowed
Data Order
Yes (data must be sorted) No
Affected
Advantage:
• Primary Index is more efficient for searching by primary key, and requires less space
(because it's sparse).
• Secondary Index is more flexible, allowing indexing on any field, including non-unique
ones.
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Given Relation:
• student_id → name
(Each student has a unique name)
• coursecode → coursename
(Each coursecode maps to one course name)
• {student_id, coursecode} → marks
(Marks depend on both student and course combination)
1. student_id → name
2. coursecode → coursename
1. Update Anomaly
• If the course name for a course changes, it must be updated in all rows where the
course is listed.
2. Insertion Anomaly
3. Deletion Anomaly
• If a student is deleted, and they were the only one enrolled in a course, the course
information is lost too.
• Unique tuples
2NF Rule: Remove partial dependencies (i.e., when a non-prime attribute depends only on
part of the primary key).
Primary Key: {student_id, coursecode} (since a student can take many courses)
Partial Dependencies:
• student_id → name
• coursecode → coursename
1. Student(student_id, name)
2. Course(coursecode, coursename)
3NF Rule: No transitive dependencies – non-prime attributes must depend only on the key.
1. Student(student_id, name)
2. Course(coursecode, coursename)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Definition:
Example:
Sample Data:
Here, we have redundancy because Hobby and Language are independent but are repeated in
combinations.
MVD Present:
• StudentID ↠ Hobby
• StudentID ↠ Language
1. Student_Hobby(StudentID, Hobby)
2. Student_Language(StudentID, Language)
A – Atomicity:
All operations in a transaction are treated as a single unit — either all succeed or none.
C – Consistency:
The database must remain in a valid state before and after the transaction.
I – Isolation:
Concurrent transactions must execute as if they were run one after another, without
interference.
D – Durability:
Once a transaction is committed, its changes are permanent, even in case of a crash.
Example: Money Transfer
BEGIN;
COMMIT;
If the system crashes after the first update, Atomicity ensures both operations are rolled back.
Definition:
• Transaction start/end
Example:
Log Entries:
<START T1>
<COMMIT T1>
Definition:
A Natural Join combines two tables based on common attributes (same name and domain),
automatically removing duplicate columns.
Example:
Tables:
Course(CourseID, Title)
Query:
How It Works:
Pseudo Code:
if [Link] = [Link]:
output (r ⋈ s)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Definition:
In Object-Oriented DBMS (OODBMS) and Object-Relational DBMS (ORDBMS), complex data
types refer to user-defined and nested data types, unlike basic types (INT, VARCHAR) used in
RDBMS.
• Tuples (records/objects)
• Arrays
• Lists
• Nested tables
• User-defined objects
Example (ORDBMS):
street VARCHAR(50),
city VARCHAR(50),
zip INT
);
emp_id INT,
name VARCHAR(50),
address AddressType
);
Definition:
Type inheritance allows one object type to inherit attributes and methods from another, just
like in object-oriented programming.
Example:
-- Base type
name VARCHAR,
age INT
) NOT FINAL;
-- Subtype
course VARCHAR
);
Definition:
ODL is used to define object types, attributes, methods, and relationships in Object-
Oriented DBMS.
Example:
interface Student {
};
ODL lets you define object schemas like how DDL is used in RDBMS.
Definition:
Example:
│ │
Product [Sales]
│ │
Region ─────────────────────────
(i) Classification
Definition:
Example:
Classifying emails as "Spam" or "Not Spam" using attributes like subject, sender, frequency of
keywords.
(ii) Clustering
Definition:
Clustering is an unsupervised learning technique used to group similar data points without
predefined labels.
Example:
• Premium buyers
• Seasonal buyers
(based on spending habits, location, frequency)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
(i) Entities:
1. Student
2. Programme
3. Fee_Payment
1. Student
• Name
• Contact_Phone
2. Programme
• Programme_Name
• Duration
• Fee
3. Fee_Payment
• Amount_Paid
• Payment_Date
(iii) Relationships:
1. Student–Enrolled–Programme
o (Many-to-One) relationship.
2. Student–Makes–Fee_Payment
o (One-to-Many) relationship.
(iv) ER Diagram:
Note:
• Student: Student_ID
• Programme: Programme_Code
• Fee_Payment: Payment_ID
• Student.Programme_Code → Programme.Programme_Code
• Fee_Payment.Student_ID → Student.Student_ID
Other Constraints:
• Amount_Paid ≥ 0.
-- Programme Table
Programme(
Programme_Name,
Duration,
Fee
);
-- Student Table
Student(
Name,
Contact_Phone,
Programme_Code,
);
-- Fee_Payment Table
Fee_Payment(
Student_ID,
Amount_Paid,
Payment_Date,
);
Relations:
SELECT account_number
FROM Account
ORDER BY name;
SELECT account_number
FROM Account
WHERE balance = (
SELECT MAX(balance)
FROM Account
);
If multiple accounts have the same highest balance, this will return all of them.
(iii) List the branch-code, account-number, name and balance of each account.
FROM Account A
FROM Bank
GROUP BY branch_code;
A transaction is a single logical unit of work that may consist of one or more SQL operations
(like SELECT, INSERT, UPDATE, DELETE) that must either be fully completed or fully failed
(rolled back).
Example of a Transaction:
BEGIN;
COMMIT;
This is a transaction because both operations must succeed together. If the system crashes
after debiting A but before crediting B, the database would be left in an inconsistent state.
Hence, transactions ensure either both updates happen or neither.
When multiple transactions run at the same time (concurrently), data integrity issues may
arise if proper isolation is not maintained. These are called concurrency problems.
1. Lost Update
2. Dirty Read
3. Non-Repeatable Read
4. Phantom Read
T1 updates to ₹10,500
T2 updates to ₹9,000
Why is it a problem?
The ₹500 deposit by T1 is lost because T2 overwrote the balance without knowing T1's change.
This leads to data inconsistency.
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
The relational model is a way of organizing data into tables (called relations). Each table
represents an entity and is made up of rows (records or tuples) and columns (attributes or
fields).
6. Foreign Key: Refers to the primary key of another table (used to define relationships).
Example:
Student Table
Programme Table
Programme_Code Programme_Name Duration
Here:
Data
Rows and columns Objects with attributes and methods
Representation
Inheritance
Not supported Supported
Support
Complex Data Limited support (e.g., arrays in Full support for complex data (e.g.,
Types PostgreSQL) multimedia)
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
Student Table
|------------|--------|------------------------|
|------------|-------|---------------|
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4. Backup and Recovery: Automatically backs up data and restores it after failure.
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
An index is a data structure that improves the speed of data retrieval operations on a database
table.
Types of Indexes:
Example:
Name VARCHAR(50),
Department VARCHAR(30)
);
o Secondary index helps, but primary index is more efficient due to uniqueness
and better data organization.
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
What is SQL?
SQL (Structured Query Language) is a standard language used to interact with relational
databases. It includes:
Name VARCHAR(50),
Programme_Code VARCHAR(10),
Phone_Number VARCHAR(15)
);
This command creates a Student table with specified fields and data types. The PRIMARY KEY
ensures uniqueness of Student_ID.
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Relationships in ER Diagram
Example:
• Each student has one ID card, and each ID card belongs to only one student.
Diagram:
1 1
Example:
• Students can enroll in many courses, and each course can have many students.
Diagram:
M N
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Lossless Join Decomposition means breaking a relation into two or more sub-relations in such
a way that no data is lost when joining them back.
Definition:
A decomposition of relation R into R1 and R2 is lossless if:
R1 ⨝ R2 = R
Example:
We decompose it into:
• R1(Student_ID, Name)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Three Levels:
Diagram:
+-------------------+
| External Level |
| (User Views) |
+-------------------+
+-------------------+
| Conceptual Level |
| (Logical Schema) |
+-------------------+
+-------------------+
| Internal Level |
| (Physical Storage)|
+-------------------+
Data Independence:
• Logical Data Independence: Changes in conceptual level don’t affect external views.
• Physical Data Independence: Changes in physical storage don’t affect logical schema.
Example:
If we add an index to improve speed (physical level), user queries remain the same — that’s
physical data independence.
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Example:
PK = (Course_ID, Student_ID)
2NF Decomposition:
1. Student(Student_ID, Student_Name)
2. Course_Student(Course_ID, Student_ID)
3. Course(Course_ID, Course_Name)
3NF (Third Normal Form):
o It is in 2NF
Example:
PK = Emp_ID
3NF Decomposition:
2. Department(Dept_ID, Dept_Name)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Data Recovery is the process of restoring the database to a correct state after a failure.
Causes of Failure:
• System crash
• Transaction failure
• Disk crash
• Power failure
• Checkpoints
Suppose a transaction debits ₹1000 but crashes before completion. Recovery uses the log to
rollback this partial update.
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
* Query Optimization
Query Optimization is the process of choosing the most efficient query execution plan to
improve performance.
Example:
The optimizer chooses the best plan using stats, indexes, etc.
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Given:
• R = {A, B, C, D, E}
• FDs:
o A → BC
o B→E
o C→D
Start with A:
• A → BC
• B→E
• C→D
So, A → B, C → D, E
Hence, A+ = {A, B, C, D, E} = all attributes
Candidate Key = A
Since A is the only key, and all dependencies are on A or its dependent attributes, it's already
in 2NF.
• A→B
• A→C
3NF Decomposition:
1. R1(A, B, C) – from A → BC
2. R2(B, E) – from B → E
3. R3(C, D) – from C → D
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Definition:
Data Mining is the process of extracting useful patterns, knowledge, or insights from large
amounts of data using statistical, machine learning, or AI techniques.
Example:
Raw Data → Data Cleaning → Data Mining → Pattern Discovery → Decision Making
Definition:
A Data Warehouse is a central repository of integrated data collected from multiple sources,
used for analysis and reporting.
Features:
• Subject-oriented
• Integrated
• Time-variant
• Non-volatile
Example:
A company collects sales data from different stores and stores it in a warehouse. Analysts can
then use this data to generate monthly or yearly sales reports.
Diagram:
↓ ↓ ↓
Business Intelligence
Definition:
NoSQL (Not Only SQL) databases are designed to handle unstructured or semi-structured
data, offering flexibility and scalability for big data and real-time applications.
Types:
Example:
A social media app stores posts with flexible fields using MongoDB:
"user": "Abhi",
"likes": 102,
Definition:
Locking is a concurrency control mechanism used to prevent inconsistency and conflict when
multiple transactions access the same data simultaneously.
Types of Locks:
Example:
Diagram:
Definition:
A Weak Entity is an entity that cannot be uniquely identified by its own attributes alone and
needs a foreign key (from another entity) to be uniquely identified.
Example:
ER Diagram:
| |
| |
|________(PK+FK)____|
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
(i) Entities:
1. Customer
2. Account
1. Customer
• Name
• Address
• Phone
2. Account
• Balance
1. Customer–owns–Account
o Many-to-Many relationship
(iv) Constraints:
Primary Keys:
• Customer(Customer_ID)
• Account(Account_Number)
• Ownership(Customer_ID, Account_Number)
Foreign Keys:
• Ownership.Customer_ID → Customer.Customer_ID
• Ownership.Account_Number → Account.Account_Number
Other Constraints:
• Balance ≥ 0
(v) ER Diagram:
| Phone |
+-------------+
1. Customer Table:
Name VARCHAR(100),
Address VARCHAR(200),
Phone VARCHAR(15)
);
2. Account Table:
Account_Type VARCHAR(50),
Balance DECIMAL(10, 2)
);
Customer_ID INT,
Account_Number INT,
);
This structure:
• Allows queries like “Find all accounts owned by a customer” and vice versa
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Relations Given:
(i) Find the course_code and title of those courses whose duration is more than one
month:
FROM Course
(ii) List the title of the course taken by the student whose enrol_no is ‘S01’:
SELECT [Link]
FROM Student S
FROM Course;
(iv) List the enrol_no, name, title, duration for all the students:
FROM Student S
When multiple transactions are executed concurrently, they can interfere with each other and
cause data inconsistency if proper isolation is not maintained. The major problems of
concurrent transactions are:
Occurs when two transactions read the same data and then update it, but the second update
overwrites the first one.
Example:
2. Dirty Read
Occurs when one transaction reads data written by another transaction that has not yet been
committed.
Example:
3. Non-repeatable Read
Occurs when a transaction reads the same data twice and gets different values because
another transaction updated the data in between.
Example:
4. Phantom Read
Occurs when a transaction re-executes a query and sees new rows added by another
committed transaction.
Example:
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1. Data Mining
• Definition: The process of discovering patterns, trends, and useful information from
large datasets using AI/ML/statistics.
2. Data Warehousing
• Definition: A centralized repository that stores historical and integrated data from
multiple sources to support reporting and analysis.
• Example: A company stores all sales data from different branches in a data warehouse.
Relation to DBMS:
• A Data Warehouse uses a DBMS to store, manage, and query large volumes of data.
• Data is often extracted from DBMS, transformed, and loaded into a warehouse (ETL
process).
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Referential Integrity ensures that foreign key values in a table must match primary key
values in another (or the same) table — or be NULL (if allowed).
Example:
Tables:
Customer
Customer_ID | Name
------------|----
C001 | Riya
C002 | Aman
Order
---------|-------------|-------
Here:
Customer_ID VARCHAR(10),
Amount DECIMAL,
);
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Given:
• Relation:
R={A,B,C,D,E,F}R = \{A, B, C, D, E, F\}R={A,B,C,D,E,F}
We need to find the candidate key(s) of R — i.e., attribute(s) whose closure contains all
attributes in R.
Compute A⁺:
Start with:
A⁺ = {A}
A⁺ = {A, B, C, D, E, F} = R
1NF requires atomic values — this is assumed to be satisfied (as not specified otherwise).
2NF:
• Must be in 1NF
So R is already in 2NF
3NF condition:
A relation is in 3NF if for every functional dependency X → Y, one of the following holds:
2. X is a superkey, or
• B is not a superkey
• D is not a superkey
3NF Decomposition
R2(B, E)
R3(D, C, F)
1. R1(A, B, D) – from A → BD
2. R2(B, E) – from B → E
3. R3(D, C, F) – from D → CF
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1. Lossless Decomposition
Decompose into:
• R1(A, B)
• R2(A, C)
Now, join:
R1 ⨝ R2 = R (original relation)
This is lossless because attribute A (a key in R1) is common and functionally determines B
and C.
Original FDs:
• A→B
• B→C
• R1(A, B)
• R2(B, C)
• A → B is in R1
• B → C is in R2
Note:
1. Atomicity
o Example: Transfer ₹1000 — debit & credit both must succeed or none.
2. Consistency
3. Isolation
o Concurrent transactions should not interfere with each other.
o Example: One user reading data should not see partial updates.
4. Durability
• Hides complexity
Example:
Student sees only their grades, not full tables.
Example:
Tables like Student, Course, and their relationships
Example:
Indexing on Student_ID, storage in disk blocks
Diagram:
+-------------------+
| External Level |
| (User Views) |
+-------------------+
↓
+-------------------+
| Conceptual Level |
| (Logical Schema) |
+-------------------+
+-------------------+
| Internal Level |
| (Physical Storage)|
+-------------------+
What is Recovery?
Database Recovery is the process of restoring the database to a consistent state after a
failure (crash, power loss, etc.).
Example:
Transaction T1:
• Log:
[START T1]
[COMMIT T1]
• If the system crashes after the update but before commit, recovery uses logs to
rollback.
OODBMS vs RDBMS
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Query Optimisation:
• It is the process where the DBMS chooses the most efficient query execution plan
from among many alternatives, based on cost estimation (I/O, CPU time, etc.).
Example:
Goal Find most efficient execution plan Actually run the plan and get result
• Ability to change the logical schema (tables, relationships) without affecting external
views.
Example:
Example:
Locking:
Locking is a technique to ensure that multiple transactions accessing the same data do not
lead to inconsistency.
Types of Locks:
Without Locking:
With Locking:
A join combines rows from two or more tables based on a related column.
Example:
FROM Student
A weak entity:
Example:
• Primary Index: Built on a primary key, ensures unique and sorted entries
Example:
(d) Deadlock
A deadlock occurs when two or more transactions are waiting for each other’s resources,
resulting in an infinite wait.
Example:
• Encryption
• Auditing
Example:
• A user must have SELECT permission on the Payroll table to view salaries.
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1. Member
2. Book
3. Issue (associative entity for the issue transaction between Member and Book)
1(a)(ii) Attributes of Each Entity
1. Member
• Member_Name
2. Book
• Title
3. Issue
• Issue_Date
• Return_Date
• Member–Issues–Book
→ A many-to-many relationship with attributes (issue date, return date)
→ A member can issue multiple books, and a book can be issued by different
members at different times.
| Return_Date|
+------------+
1(a)(v) List of Constraints
Primary Keys:
• Member(Member_ID)
• Book(Book_Code)
Foreign Keys:
• Issue.Member_ID → Member.Member_ID
• Issue.Book_Code → Book.Book_Code
Other Constraints:
• Dates must follow logical constraints: Issue_Date < Return_Date (if not null)
1. Member Table
Member_Name VARCHAR(100)
);
2. Book Table
Title VARCHAR(200)
);
3. Issue Table
Member_ID INT,
Book_Code INT,
Issue_Date DATE,
Return_Date DATE,
);
• Supports multiple issues of the same book by the same member (on different dates).
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Given Relations:
(i) List all names of all the hospitals in the alphabetical order of hospital name:
SELECT Hospital_name
FROM Hospital
(ii) Find the number of doctors working in the hospital whose Hospital_ID = 'HO1':
FROM Doctor
FROM Hospital H
(iv) Find the name of all the doctors whose specialization is "Physician":
SELECT Name
FROM Doctor
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
A transaction must be completed entirely or not executed at all. If it fails at any point, the
database must roll back to its previous consistent state.
Example of a Transaction:
BEGIN;
COMMIT;
If there's a power failure after deducting from A but before adding to B, this could lead to data
inconsistency. That's where the properties of transactions come in.
The four properties that ensure the reliability of transactions are ACID:
1. Atomicity
Example:
If money is deducted from A but not added to B, the system will roll back to the original state.
2. Consistency
Example:
If a rule says the total bank balance must remain ₹10,000, after the transfer, this must still be
true.
3. Isolation
Example:
If two users transfer money at the same time, they shouldn't see partial or conflicting data
during their operations.
4. Durability
• Once a transaction is committed, its changes are permanently stored, even in case of
system failure.
Example:
After transferring funds and committing, the new balances must persist even if there's a power
cut immediately afterward.
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Definition:
Complex data types are data types that go beyond standard atomic types like INT, VARCHAR,
or DATE. They allow storage of non-atomic or structured data such as arrays, sets, lists,
objects, or even multimedia (images, videos).
Features:
street VARCHAR,
city VARCHAR,
pincode INT
);
name VARCHAR,
contact Address
);
Definition:
Features:
An e-commerce company stores all past sales, customer behavior, and product data in a data
warehouse to analyze trends and generate business reports.
Classification is a supervised learning technique in data mining used to categorize data into
predefined classes or labels based on historical data.
Features:
• Uses algorithms like Decision Trees, Naive Bayes, SVM, Random Forest
Example:
Predicting if an email is "Spam" or "Not Spam" based on features like subject, sender, and
content.
Definition:
Clustering is an unsupervised learning technique used to group similar data points into
clusters based on similarity, without predefined labels.
Features:
Example:
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
• It hides the physical details and shows entities, relationships, attributes, and
constraints.
Example:
A conceptual schema might define a Student table with Roll_No, Name, and Course_ID —
without specifying how it's stored on disk.
Example Tasks:
• It ensures data blocks are read from and written to disk correctly.
Example:
When a SELECT query is issued, the File Manager retrieves the appropriate blocks from disk via
the OS.
• Definition: A special read-only database that stores metadata (data about data) such
as table names, column types, user info, constraints, and indexes.
Example:
The data dictionary may store:
Example:
Company
├── Department
├── Employee
Table: STUDENT
1 Aditi C1
2 Rahul C2
3 Neha C1
Table: COURSE
Course_ID Title
C1 DBMS
C2 Java
C3 Python
Result:
Name
Aditi
Rahul
Name
Neha
Result:
1 Aditi C1
3 Neha C1
• Definition: Combines every row of one table with every row of another.
Example:
1 Aditi C1 C1 DBMS
1 Aditi C1 C2 Java
1 Aditi C1 C3 Python
• Definition: Combines rows from two tables with same structure, removes
duplicates.
Example:
Suppose we have:
Table A:
Name
Aditi
Neha
Table B:
Name
Rahul
Neha
UNION
Result:
Name
Aditi
Neha
Rahul
• Definition: Returns rows that are in the first table but not in the second.
Example:
EXCEPT
Result:
Name
Aditi
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Given Schema:
1. Customer_ID → Customer_name
(Since each customer ID is unique and gives name)
Given:
• Account_No is unique for each account and identifies the customer as well.
Anomalies:
1. Update Anomaly:
o If Aditi Sharma changes her name, you need to update it in multiple rows
(A1001, A1002).
2. Insertion Anomaly:
o For example, if a customer wants to register but hasn't opened an account yet,
you can't store their name.
3. Deletion Anomaly:
o If you delete the last account of a customer, their name and ID are lost too.
2NF removes partial dependencies, but the current relation is in 1NF and also in 2NF since
the primary key Account_No is not composite. So no partial dependency is possible.
In this relation:
• So we decompose to remove it
3NF Decomposition:
Customer(Customer_ID, Customer_name)
Keys:
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Definition:
A Lossless Join Decomposition ensures that when a relation is decomposed into two or more
sub-relations, and then joined back, it reconstructs the original relation exactly, without any
loss of data or creation of spurious tuples.
• R1(Student_ID, Name)
We can join R1 and R2 on Student_ID to get back original relation without losing information,
so it's a lossless decomposition.
If we decompose into:
• R1(Name, Course_ID)
• R2(Course_ID, Course_Name)
And try to join on Course_ID, we might get spurious Name–Course combinations (e.g.,
assigning wrong student names to courses).
Example:
Serial Schedule:
mathematica
CopyEdit
T1: Read A
T2: Read B
T1: Write A
T2: Write B
• Two phases:
Example:
Example:
If T1 updated a row but didn’t commit and system crashed, its changes are undone during
recovery.
(iv) Checkpoint
• A checkpoint is a snapshot of the current state of the database (and log positions),
written periodically to help with faster recovery.
• During recovery, the system starts from the last checkpoint instead of scanning the
entire log.
Example:
Checkpoint at 12:00 PM → crash at 12:05 PM
Recovery starts from 12:00 PM onward only
(v) Authorization
Example:
• The query cost refers to the amount of resources (CPU, disk I/O, memory, network)
used to execute a query.
• Most important measure = Disk I/O operations, as disk access is slower than memory.
Suppose:
• No index is available
Example:
SELECT * FROM Employee WHERE Age = 30;
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Query
Uses OQL (Object Query Language) Uses SQL
Language
Goal Assign new data to predefined categories Group similar data points into clusters
Primary Simple or surrogate key (joins with fact Composite key (made of foreign keys from
Key table) dimensions)
Denormalized (star/snowflake
Schema Design Highly normalized (3NF)
schema)
Locking mechanisms, such as shared and exclusive locks, prevent data inconsistency by controlling access to data items during concurrent transactions . Shared locks allow multiple read operations but prevent write operations on the locked data, while exclusive locks prevent other transactions from accessing the locked data in any capacity . Without these locks, issues such as lost updates, where multiple transactions overwrite each other's updates, and dirty reads, where one transaction reads data altered by another uncommitted transaction, can occur, leading to data inconsistency .
OODBMS stores data as objects, similar to object-oriented programming, supporting complex data types, inheritance, encapsulation, and polymorphism, making it suitable for applications involving multimedia, CAD/CAM, and simulations . Conversely, RDBMS employs a tabular format, focusing on tables and rows, supporting traditional business applications like banking and e-commerce due to its structured query language (SQL) and robust transaction processing . The choice between the two depends on the nature of data and required functionalities, where RDBMS excels in structured data management and OODBMS in handling complex data .
The ANSI/SPARC three-level database architecture consists of the external, conceptual, and internal levels. The external level caters to user views and hides system complexity . The conceptual level represents the logical structure of the entire database, detailing the entities, attributes, and relationships . The internal level addresses the physical storage of data, including indexing and file organization . This architecture provides data abstraction by allowing changes in one level without affecting other levels, enabling logical and physical data independence, and streamlining database management .
Fact tables store measurable business metrics and are composed of numerical data, usually related to transactions or events, with a composite key made of foreign keys from related dimension tables . Dimension tables contain descriptive attributes (textual or categorical) and help contextualize the data stored in fact tables, often using a simple or surrogate key . The combination allows for analysis and reporting by enabling complex queries to compute metrics across different dimensions, contributing to the overall analytical power of the data warehouse .
Checkpoints are crucial in database recovery as they mark a specific point in time where the state of the database and its log positions are saved to disk . They optimize recovery processes by allowing the system to start recovery from the checkpoint instead of reprocessing the entire log, significantly reducing the time needed to restore the database to a consistent state . By providing a reset point, checkpoints ensure that only the transactions occurred after the checkpoint need to be reviewed and either redone or undone, effectively optimizing database recovery time .
ACID properties—Atomicity, Consistency, Isolation, and Durability—are essential for reliable transaction management. Atomicity ensures transactions are all-or-nothing, so partial changes are not left incomplete . Consistency maintains database integrity before and after transactions, while Isolation ensures concurrent transactions don’t interfere inconsistently . Durability guarantees completed transactions persist regardless of subsequent system failures . Absence of these properties could lead to partial updates being saved, data inconsistencies from concurrent operations, uncommitted changes being lost, and system states not reflecting completed transactions, all leading to unreliable databases .
Concurrent transaction processing can lead to issues such as the lost update problem, dirty reads, non-repeatable reads, and phantom reads . These issues arise when transactions interleave improperly, causing data inconsistency or making transactions see an inconsistent database state. Database systems mitigate these problems through locking mechanisms (shared and exclusive locks), isolation levels (e.g., serializable), and concurrency control techniques like two-phase locking . These strategies ensure that transactions access data in a controlled manner, preserving consistency across operations .
The key constraints include primary keys, foreign keys, and other constraints. Primary keys are CustomerID for Customer, AccountNumber for Account, and TransactionID for Transaction, ensuring each record is unique and identifiable . Foreign keys are used to establish referential integrity: Account.CustomerID references Customer.CustomerID, and Transaction.AccountNumber references Account.AccountNumber. Other constraints include ensuring CustomerID, AccountNumber, and TransactionID are unique and NOT NULL, balances and amounts must be non-negative, and transaction types must be either 'Withdrawal' or 'Deposit'. All these constraints maintain data integrity across related tables .
Indexes significantly improve query performance by reducing the amount of data that must be scanned to locate desired records. A primary index on a primary key ensures uniqueness and fast lookups, while a secondary index on non-key attributes speeds up search operations for those fields . However, the trade-off of using indexes is increased storage requirements and overhead on data modification operations, as indexes must be updated alongside the main data . Thus, while beneficial for read-heavy operations, careful management of indexes is necessary to avoid performance degradation during writes .
First Normal Form (1NF) ensures that each column in a table contains atomic, indivisible values, and that each row is unique without repeating groups or arrays. If 1NF is violated, data redundancy and inconsistency can occur, as multiple values in a single field prevent efficient querying and updating . For example, a table field containing multiple phone numbers would violate 1NF, necessitating separation of these entries into unique rows to comply with normalization rules .