Docsity

DBMS – Complete Summary with SQL Examples, Normalization & ACID (2026), Summaries of Database Management Systems (DBMS)

Toggle sidebar
bg1
Database Management Systems (DBMS) – Key
Concepts
Complete Summary with SQL Examples, Normalization &
ACID Properties
Table of Contents
1. Introduction to DBMS
2. Database Architecture & Models
3. The Relational Model
4. SQL Fundamentals
5. Normalization
6. ACID Properties & Transactions
7. Concurrency Control
8. Indexing & Query Optimization
9. Entity-Relationship (ER) Modeling
10. Quick Reference Tables
11. Key Takeaways
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a

Partial preview of the text

Download DBMS – Complete Summary with SQL Examples, Normalization & ACID (2026) and more Summaries Database Management Systems (DBMS) in PDF only on Docsity!

Database Management Systems (DBMS) – Key

Concepts

Complete Summary with SQL Examples, Normalization &

ACID Properties

Table of Contents

1. Introduction to DBMS

2. Database Architecture & Models

3. The Relational Model

4. SQL Fundamentals

5. Normalization

6. ACID Properties & Transactions

7. Concurrency Control

8. Indexing & Query Optimization

9. Entity-Relationship (ER) Modeling

10. Quick Reference Tables

11. Key Takeaways

1. Introduction to DBMS

Definition: A Database Management System (DBMS) is software that enables users

to define, create, maintain, and control access to a database. It acts as an

intermediary between the user and the raw data.

Why Not Just Files?

● Redundancy and inconsistency (same data in multiple files)

● Difficulty in accessing data (need custom programs for each query)

● Data isolation (data scattered across files and formats)

● Integrity problems (constraints hard to enforce)

● Atomicity problems (partial updates on crash)

● Concurrent access anomalies (no coordination)

● Security problems (no fine-grained access control)

Key Components of a DBMS:

Component Function Query Processor Parses, optimizes, and executes SQL queries Storage Manager Manages disk space, buffers, and file organization Transaction Manager Ensures ACID properties and concurrency control Catalog / Data Dictionary Stores metadata (schema, constraints, users) Authorization Manager Controls user access and permissions

NoSQL (Key-Value) Simple key → value pairs Redis, DynamoDB NoSQL (Column-family) Tables with flexible columns Cassandra, HBase NoSQL (Graph) Nodes and edges for relationships Neo4j Object-Oriented Objects with attributes and methods db4o Hierarchical Tree structure (parent-child)

IBM IMS

Network Graph structure with pointers

IDMS

2.2 Relational vs. NoSQL Feature Relational (SQL) NoSQL Schema Fixed, predefined Flexible, dynamic Consistency Strong (ACID) Eventual (BASE) Scalability Vertical (bigger server) Horizontal (more servers) Query Language SQL Varies (often JSON-based) Best For Structured data, complex queries Unstructured data, high throughput

2.3 DBMS vs. File System Aspect File System DBMS Data redundancy High Low (normalized) Concurrent access Poor Excellent Query capability None (must write code) SQL (declarative) Recovery Manual Automatic (WAL, logs) Security File-level Row/column-level Integrity Application-enforced DBMS-enforced

3. The Relational Model

Definition: Data is organized into relations (tables). Each table has a fixed set of

attributes (columns) and contains tuples (rows). Each row represents a single entity

instance.

3.1 Key Terminology Term Definition Example Relation A table Students Tuple A row (1, "Alice", 20) Attribute A column name, age

Example:

sql CREATE TABLE Students ( student_id INT PRIMARY KEY, -- primary key email VARCHAR(100) UNIQUE, -- alternate/candidate key name VARCHAR(50) NOT NULL, department_id INT, FOREIGN KEY (department_id) REFERENCES Departments(department_id) ); 3.3 Integrity Constraints Constraint Description Entity Integrity Primary key cannot be NULL Referential Integrity Foreign key must reference an existing row (or be NULL) Domain Integrity Values must belong to the attribute's domain Key Integrity Primary key values must be unique User-defined Custom business rules (e.g., salary > 0)

4. SQL Fundamentals

SQL (Structured Query Language) is the standard language for relational databases.

It is divided into several sub-languages:

Sub-language Purpose Commands DDL (Data Definition) Define/modify schema CREATE, ALTER, DROP, TRUNCATE DML (Data Manipulation) Modify data INSERT, UPDATE, DELETE DQL (Data Query) Retrieve data SELECT DCL (Data Control) Manage permissions GRANT, REVOKE TCL (Transaction Control) Manage transactions COMMIT, ROLLBACK, SAVEPOINT 4.1 DDL — Creating Tables sql CREATE TABLE Employees ( emp_id INT PRIMARY KEY AUTO_INCREMENT, first_name VARCHAR(50) NOT NULL, last_name VARCHAR(50) NOT NULL, salary DECIMAL(10,2) CHECK (salary > 0), hire_date DATE DEFAULT CURRENT_DATE, dept_id INT, FOREIGN KEY (dept_id) REFERENCES Departments(dept_id) ); ALTER TABLE Employees ADD COLUMN email VARCHAR(100); ALTER TABLE Employees DROP COLUMN email; DROP TABLE Employees;

sql SELECT dept_id, COUNT(*) AS num_employees, AVG(salary) AS avg_salary FROM Employees GROUP BY dept_id HAVING AVG(salary) > 60000;

JOINS:

Join Type Description Returns INNER JOIN (^) Matches in both tables Only matching rows LEFT JOIN All rows from left + matches NULLs for non-matches on right RIGHT JOIN (^) All rows from right + matches NULLs for non-matches on left FULL OUTER JOIN (^) All rows from both NULLs where no match CROSS JOIN (^) Cartesian product All combinations SELF JOIN Join a table to itself E.g., employee → manager sql -- INNER JOIN example SELECT e.first_name, d.dept_name FROM Employees e INNER JOIN Departments d ON e.dept_id = d.dept_id; -- LEFT JOIN example (include employees with no department) SELECT e.first_name, d.dept_name FROM Employees e LEFT JOIN Departments d ON e.dept_id = d.dept_id;

Subqueries:

sql -- Employees earning more than the average SELECT first_name, salary FROM Employees WHERE salary > (SELECT AVG(salary) FROM Employees); -- Employees in departments located in 'New York' SELECT first_name FROM Employees WHERE dept_id IN ( SELECT dept_id FROM Departments WHERE location = 'New York' );

Set Operations:

Operation Description UNION Combine results, remove duplicates UNION ALL Combine results, keep duplicates INTERSECT (^) Rows in both results EXCEPT / MINUS Rows in first but not second

Window Functions:

sql -- Rank employees by salary within each department SELECT first_name, dept_id, salary, RANK() OVER (PARTITION BY dept_id ORDER BY salary DESC) AS rank FROM Employees;

Common Window Functions: ROW_NUMBER(), RANK(), DENSE_RANK(), NTILE(), LEAD(),

LAG(), SUM() OVER(...)

● Violation: A phone_numbers column storing "555-1234, 555-5678"

● Fix: Create a separate PhoneNumbers table with one row per number

2NF (Second Normal Form)

● Rules: Must be in 1NF + no partial dependencies (non-key attributes must

depend on the entire primary key)

● Violation: (StudentID, CourseID) → StudentName — StudentName depends

only on StudentID, not the full composite key

● Fix: Move StudentName to a Students table

3NF (Third Normal Form)

● Rules: Must be in 2NF + no transitive dependencies (non-key attributes must

not depend on other non-key attributes)

● Violation: EmployeeID → DeptID → DeptName — DeptName depends on

DeptID, not directly on EmployeeID

● Fix: Move DeptName to a Departments table

BCNF (Boyce-Codd Normal Form)

● Rule: For every functional dependency X → Y, X must be a super key

● Stronger than 3NF: Handles certain edge cases where 3NF still has anomalies

● Violation: A table with overlapping candidate keys

4NF & 5NF

● 4NF: No multi-valued dependencies (beyond BCNF)

● 5NF: No join dependencies (beyond 4NF)

● Note: In practice, 3NF or BCNF is sufficient for most applications.

5.3 Normalization Example

Unnormalized:

StudentID StudentName Courses Advisor 1 Alice DB, OS Dr. Smith 2 Bob DB Dr. Jones

1NF (atomic values — separate rows for each course):

StudentID StudentName Course Advisor 1 Alice DB Dr. Smith 1 Alice OS Dr. Smith 2 Bob DB Dr. Jones

2NF (remove partial dependency — StudentName depends only on StudentID):

● Students: (StudentID, StudentName, Advisor)

● Enrollments: (StudentID, Course)

3NF (remove transitive dependency — if StudentID → Advisor → AdvisorOffice):

● Students: (StudentID, StudentName, AdvisorID)

● Advisors: (AdvisorID, AdvisorName, AdvisorOffice)

● Enrollments: (StudentID, Course)

5.4 Denormalization

● Definition: Intentionally introducing redundancy to improve read performance.

● When to use: Data warehouses, reporting systems, read-heavy workloads.

● Trade-off: Faster reads, slower writes, more storage, potential inconsistency.

6. ACID Properties & Transactions

Transaction: A logical unit of work that must be executed as a single, indivisible

operation.

6.1 ACID Properties Property Definition Example

6.3 Transaction Control (SQL) sql BEGIN TRANSACTION; UPDATE Accounts SET balance = balance - 500 WHERE account_id = 1; UPDATE Accounts SET balance = balance + 500 WHERE account_id = 2; -- If both succeed: COMMIT; -- If something went wrong: ROLLBACK; -- Partial rollback: SAVEPOINT before_update; -- ... more operations ... ROLLBACK TO before_update; 6.4 BASE (NoSQL Counterpart) Property Meaning Basically Available System is available even during partial failures Soft State State may change over time without input Eventual Consistency Data will eventually be consistent across nodes

ACID vs. BASE: ACID prioritizes consistency; BASE prioritizes availability. Choose

based on your application's needs (banking → ACID; social media → BASE).

7. Concurrency Control

Problem: Concurrent transactions can cause anomalies:

Anomaly Description Example Dirty Read Reading uncommitted data T1 updates a row; T2 reads it; T1 rolls back → T2 has invalid data Non-repeatable Read Same query returns different results T1 reads a row; T2 updates it; T1 reads again → different value Phantom Read New rows appear between reads T1 reads all rows matching a condition; T2 inserts a new matching row; T reads again → extra row Lost Update Two transactions update the same data; one overwrites the other T1 and T2 both read value 100; both add 10; final = 110 instead of 120 7.1 Locking Lock Type Description Shared (S) Multiple transactions can read (but not write) Exclusive (X) Only one transaction can read or write

7.3 Deadlock Handling Strategy Description Prevention Timestamp ordering (wait-die, wound-wait) Detection Wait-for graph; find cycles Recovery Abort one transaction in the cycle (victim selection)

Wait-Die: Older transaction waits; younger transaction dies (rolls back)

Wound-Wait: Older transaction wounds (preempts) younger; younger waits

8. Indexing & Query Optimization 8.1 Indexes

Definition: A data structure that speeds up data retrieval at the cost of additional

storage and slower writes.

Index Type Description Use Case B+ Tree Balanced tree; all data in leaves; linked leaves for range queries Default in most DBMS Hash Hash table; O(1) for equality lookups Exact match queries Bitmap Bit per distinct value Low-cardinality columns (e.g., gender)

Full-text Inverted index for text search Searching documents Clustered Data rows physically ordered by index key Primary key (one per table) Non-clustered Separate structure pointing to data rows Secondary indexes

Creating an Index:

sql CREATE INDEX idx_employee_dept ON Employees(dept_id); CREATE UNIQUE INDEX idx_employee_email ON Employees(email); DROP INDEX idx_employee_dept;

When to Index:

● ✅ Columns used in WHERE, JOIN, ORDER BY

● ✅ High-cardinality columns (many distinct values)

● ❌ Small tables (full scan is faster)

● ❌ Columns with frequent writes (index maintenance overhead)

● ❌ Low-cardinality columns (e.g., boolean)

8.2 Query Execution Pipeline text SQL Query → Parser → Logical Plan → Optimizer → Physical Plan → Execution Engine → Results

Optimization Techniques:

● Predicate Pushdown — Apply filters as early as possible

● Join Reordering — Execute the most selective joins first

● Index Selection — Choose the best index for each access

● Cost Estimation — Use statistics (row counts, histograms) to estimate cost