📘 DBMS – Class Notes
1. Introduction to DBMS
Database: Collection of interrelated data.
DBMS: Software that allows creation, retrieval, updating, and management of data in
databases.
Examples: MySQL, PostgreSQL, Oracle, MongoDB.
Advantages:
Redundancy control
Data integrity
Security
Concurrency control
Backup and recovery
2. Database Models
Hierarchical Model
Network Model
Relational Model (Most common)
Object-Oriented Model
Document Model (e.g., MongoDB)
3. Relational Model
Data stored in tables (relations).
Attributes = Columns, Tuples = Rows
Schema: Structure/definition of the table
Instance: Actual content of the table at a given time
Keys:
Primary Key: Uniquely identifies tuples.
Candidate Key: All possible keys that can act as a primary key.
Super Key: Set of attributes that uniquely identify a record.
Foreign Key: Attribute that links two tables.
4. SQL (Structured Query Language)
DDL – Data Definition Language:
CREATE, ALTER, DROP, TRUNCATE
DML – Data Manipulation Language:
SELECT, INSERT, UPDATE, DELETE
DCL – Data Control Language:
GRANT, REVOKE
TCL – Transaction Control Language:
COMMIT, ROLLBACK, SAVEPOINT
Basic Query Example:
sql
Copy
Edit
SELECT name, age FROM students WHERE age > 18 ORDER BY age DESC;
5. Normalization
Process of removing redundancy and improving data integrity.
Forms:
1NF – Atomic values
2NF – No partial dependency
3NF – No transitive dependency
BCNF – Every determinant is a candidate key
6. ER Model (Entity-Relationship Model)
Entity: Object in the real world (e.g., Student)
Attributes: Properties (e.g., Roll No, Name)
Entity Set: Group of similar entities
Relationship: Association between entities
Diagram Elements:
Rectangles = Entities
Ellipses = Attributes
Diamonds = Relationships
7. Transactions and Concurrency
Transaction: A unit of work (e.g., transferring money)
ACID Properties:
Atomicity
Consistency
Isolation
Durability
Concurrency Problems:
Lost update
Dirty read
Unrepeatable read
Solutions: Locks, serializability, timestamp ordering
8. Indexing
Increases the speed of data retrieval.
Types:
Single-level index
Multi-level index
B+ Tree index (most used)
9. Joins in SQL
INNER JOIN
LEFT JOIN / RIGHT JOIN
FULL OUTER JOIN
SELF JOIN
sql
Copy
Edit
SELECT A.name, B.salary
FROM Employees A
JOIN Salaries B ON A.emp_id = B.emp_id;
10. File Organization & Storage
Heap File: Unordered records
Sorted File: Ordered records
Hashed File: Records stored using a hash function
11. NoSQL Overview
Schema-less
Stores unstructured/semi-structured data
Examples: MongoDB, Cassandra