DBMS Summary + SQL Cheat Sheet
1. What is DBMS?
A Database Management System (DBMS) is software for storing, managing, and retrieving data efficiently.
Popular DBMS: MySQL, PostgreSQL, Oracle, SQL Server.
2. DBMS vs RDBMS
- DBMS: Stores data in files, no relations.
- RDBMS: Stores data in tables with relations (keys).
3. Keys in DBMS
- Primary Key: Uniquely identifies a row.
- Foreign Key: Refers to a primary key in another table.
- Composite Key: Multiple columns as a unique key.
- Candidate Key: Eligible to be a primary key.
- Super Key: Any set of attributes that uniquely identifies a row.
4. Normalization (To Remove Redundancy)
- 1NF: Atomic values only.
- 2NF: No partial dependency (non-key depends on part of primary key).
- 3NF: No transitive dependency (non-key depends on non-key).
- BCNF: Every determinant is a candidate key.
5. ACID Properties of Transactions
A - Atomicity: All operations succeed or none.
C - Consistency: DB remains valid before/after transaction.
I - Isolation: Transactions don't interfere.
D - Durability: Changes persist after commit.
6. Views and Indexes
- View: Virtual table from SQL query.
- Index: Speeds up data retrieval.
7. SQL Cheat Sheet
Basic Queries:
SELECT * FROM table;
SELECT col1, col2 FROM table WHERE condition;
INSERT INTO table (col1, col2) VALUES (val1, val2);
UPDATE table SET col = value WHERE condition;
DELETE FROM table WHERE condition;
Joins:
INNER JOIN: Only matched rows.
LEFT JOIN: All from left + matched from right.
RIGHT JOIN: All from right + matched from left.
FULL JOIN: All rows from both sides.
DDL: CREATE, ALTER, DROP
DML: INSERT, UPDATE, DELETE
DCL: GRANT, REVOKE
TCL: COMMIT, ROLLBACK, SAVEPOINT