โ๏ธ ACID Properties
Atomicity (All or Nothing)
Definition: Transaction is treated as a single unit - either all operations succeed or all fail.
Transfer $100 from X to Y:
T1: X = X - 100 (X becomes 400)
T2: Y = Y + 100 (Y becomes 300)
If T1 succeeds but T2 fails โ Transaction is ABORTED
Both accounts return to original state (X=$500, Y=$200)
Consistency (Integrity Constraints Maintained)
Definition: Database must remain in a valid state before and after transaction.
After: X($400) + Y($300) = $700
โ Total is maintained โ Database is CONSISTENT
Isolation (Transactions Independent)
Definition: Concurrent transactions don't interfere with each other.
Transaction T: X = X * 100; Y = Y + X
Transaction T'': Sum = X + Y
If T'' reads X after T updates it but before T updates Y:
T'' reads: X = $50,000, Y = $500 โ Sum = $50,500 โ
Correct sum should be: X = $50,000, Y = $50,500 โ Sum = $100,500 โ
Durability (Changes Persist)
Definition: Once a transaction commits, changes are permanent even if system crashes.
๐จ Database Design Process
1. Conceptual Design (ER Diagrams)
Draw Entity-Relationship diagrams showing entities, attributes, and relationships.
Relationships: Student ENROLLS-IN Course (M:N)
Attributes: Student(ID, Name, DOB, Major)
Course(CourseNo, Title, Credits)
2. Logical Design (Relational Model)
Convert ER diagrams to relational schemas (tables).
COURSE(CourseNo, Title, Credits)
ENROLLS(StudentID, CourseNo, Grade) -- Junction table for M:N
3. Optimization (Normalization)
Remove redundancy and anomalies through normal forms (1NF, 2NF, 3NF, BCNF).
๐ท ER Diagram Components
Entities (Rectangle)
Real-world objects distinguishable from other objects.
Weak Entity: DEPENDENT (depends on EMPLOYEE, identified by combination of employee SSN + dependent name)
Attributes (Oval)
| Type | Description | Example |
|---|---|---|
| Simple | Single atomic value | Age, SSN |
| Composite | Can be divided into parts | Address(Street, City, Zip) |
| Multivalued | Multiple values allowed | Phone_Numbers = {123, 456, 789} |
| Derived | Calculated from other attributes | Age (derived from BirthDate) |
Relationships (Diamond)
Cardinality Constraints:
EMPLOYEE manages DEPARTMENT
Each employee manages โค 1 department, each department has โค 1 manager
1:N (One-to-Many):
DEPARTMENT has EMPLOYEE
Each department has many employees, each employee works for 1 department
M:N (Many-to-Many):
EMPLOYEE works-on PROJECT
Each employee works on many projects, each project has many employees
Participation Constraints:
- Total Participation (Double line): Every entity must participate. Example: Every EMPLOYEE must work for a DEPARTMENT.
- Partial Participation (Single line): Not all entities need to participate. Example: Not all EMPLOYEEs manage a DEPARTMENT.
๐ Keys in Databases
Types of Keys
| Key Type | Definition | Example |
|---|---|---|
| Superkey | Any set of attributes that uniquely identifies a tuple | {SSN}, {SSN, Name}, {SSN, Age} |
| Candidate Key | Minimal superkey (no redundant attributes) | {SSN}, {EmployeeID} |
| Primary Key | Chosen candidate key (underlined) | SSN |
| Foreign Key | References primary key in another table | Dno in EMPLOYEE references Dnumber in DEPARTMENT |
| Partial Key | Part of key for weak entity (dashed underline) | Dependent_Name in DEPENDENT |
Candidate Keys:
1. {State, RegNo} - License plate is unique per state
2. {SerialNo} - VIN is globally unique
Superkeys:
{SerialNo}, {State, RegNo}, {SerialNo, Make}, {State, RegNo, Model}, etc.
Primary Key: Choose {SerialNo} (smaller)
๐ณ Enhanced ER (EER) Model
Specialization/Generalization
Subclasses:
- SECRETARY(TypingSpeed)
- ENGINEER(EngType)
- TECHNICIAN(TGrade)
A Secretary IS-A Employee (inherits all attributes)
Constraints on Specialization
| Constraint | Symbol | Meaning | Example |
|---|---|---|---|
| Disjoint | d | Entity can belong to at most ONE subclass | STUDENT is either Undergraduate OR Graduate (not both) |
| Overlapping | o | Entity can belong to MULTIPLE subclasses | EMPLOYEE can be both ENGINEER and MANAGER |
| Total | Double line | Every entity MUST belong to a subclass | Every VEHICLE is either CAR or TRUCK |
| Partial | Single line | Entity MAY NOT belong to any subclass | Not all EMPLOYEEs are MANAGERS |
Categories (Union Types)
Subclass with multiple superclasses from different entity types.
An owner can be a person OR company OR bank
(Subset of the UNION, not intersection)
๐ ER to Relational Mapping
Step 1: Regular Entity Types
Create a table for each strong entity with all simple attributes.
Relational: EMPLOYEE(SSN, Name, Address, Salary)
Step 2: Weak Entity Types
Include owner's primary key as foreign key. Combine with partial key for primary key.
DEPENDENT(ESSN, Dependent_Name, Sex, BirthDate)
FK: ESSN references EMPLOYEE(SSN)
Step 3: Binary 1:1 Relationships
Three approaches:
DEPARTMENT(Dnumber, Dname, Mgr_SSN, Start_Date)
FK: Mgr_SSN references EMPLOYEE(SSN)
Approach 2 - Merged Relation (For both total):
EMPLOYEE_DEPT(SSN, Name, Dnumber, Dname, Start_Date)
Approach 3 - Relationship Relation (For both partial):
EMPLOYEE(SSN, Name)
DEPARTMENT(Dnumber, Dname)
MANAGES(SSN, Dnumber, Start_Date)
Step 4: Binary 1:N Relationships
Put foreign key on the N side.
EMPLOYEE(SSN, Name, Dno)
FK: Dno references DEPARTMENT(Dnumber)
Step 5: Binary M:N Relationships
Create a new junction/relationship table with both primary keys as foreign keys.
PROJECT(PNumber, PName)
WORKS_ON(SSN, PNumber, Hours)
FK: SSN references EMPLOYEE(SSN)
FK: PNumber references PROJECT(PNumber)
Step 6: Multivalued Attributes
Create separate table with primary key of parent + multivalued attribute.
DEPT_LOCATIONS(Dnumber, Location)
FK: Dnumber references DEPARTMENT(Dnumber)
Step 7: N-ary Relationships (n > 2)
Create table with all participating entity primary keys as foreign keys.
FK: SName references SUPPLIER
FK: PartNo references PART
FK: ProjName references PROJECT
Step 8: Specialization/Generalization
Four Options:
EMPLOYEE(SSN, Name, Salary)
SECRETARY(SSN, TypingSpeed)
ENGINEER(SSN, EngType)
Use: Works for any specialization
Option 8B - Subclass Relations Only:
SECRETARY(SSN, Name, Salary, TypingSpeed)
ENGINEER(SSN, Name, Salary, EngType)
Use: Only for TOTAL specialization
Option 8C - Single Relation with Type Attribute:
EMPLOYEE(SSN, Name, Salary, JobType, TypingSpeed, EngType)
Use: For DISJOINT specialization
Option 8D - Single Relation with Boolean Flags:
EMPLOYEE(SSN, Name, Salary, IsSecretary, IsEngineer, TypingSpeed, EngType)
Use: For OVERLAPPING specialization
Step 9: Categories (Union Types)
Create relation with surrogate key + attributes from each superclass.
COMPANY(CompanyID, Name)
BANK(BankID, Name)
OWNER(OwnerID, PersonID, CompanyID, BankID, ...)
-- Only one of PersonID/CompanyID/BankID will be non-NULL
๐ Relational Model Concepts
Terminology Comparison
| Informal | Formal | Example |
|---|---|---|
| Table | Relation | EMPLOYEE |
| Column | Attribute | SSN, Name |
| Row | Tuple | (123, "John", ...) |
| Table Definition | Schema | EMPLOYEE(SSN, Name, Salary) |
| Populated Table | Instance/State | All rows currently in table |
Relation Characteristics
- Tuples are unordered (no inherent row order)
- Attributes are ordered in schema definition
- All values are atomic (1NF: no composite/multivalued attributes)
- Each attribute value must be from its domain
- NULL values represent unknown/unavailable/not applicable data
Constraints in Relational Model
1. Domain Constraints
Values must be from the attribute's domain.
Email VARCHAR(50) โ must be string
Grade ENUM('A','B','C','D','F') โ must be one of these
2. Key Constraints
No two tuples can have the same key value.
3. Entity Integrity Constraint
Primary key cannot be NULL.
4. Referential Integrity Constraint
Foreign key must either be NULL or match a primary key value in referenced table.
DEPARTMENT(Dnumber, Dname)
FK: Dno references Dnumber
Valid: Dno = 5 (if department 5 exists)
Valid: Dno = NULL (employee not assigned)
Invalid: Dno = 99 (if department 99 doesn't exist)
Update Operations & Anomalies
INSERT Violations:
- Domain: Wrong data type
- Key: Duplicate primary key
- Entity Integrity: NULL primary key
- Referential Integrity: Foreign key references non-existent value
DELETE Options:
- RESTRICT: Reject deletion if referenced
- CASCADE: Delete all referencing tuples
- SET NULL: Set foreign keys to NULL
Automatically deletes all EMPLOYEEs with Dno = 5
UPDATE Violations:
- Updating primary key = DELETE + INSERT
- Updating foreign key may violate referential integrity
- Updating ordinary attribute may violate domain constraint
๐พ SQL - Structured Query Language
DDL (Data Definition Language)
CREATE TABLE
Common Data Types
| Type | Description | Example |
|---|---|---|
| INT | Integer | Age INT |
| VARCHAR(n) | Variable string | Name VARCHAR(50) |
| CHAR(n) | Fixed string | SSN CHAR(9) |
| DECIMAL(p,s) | Exact decimal | Price DECIMAL(10,2) |
| DATE | Date (YYYY-MM-DD) | BirthDate DATE |
| BOOLEAN | True/False | IsActive BOOLEAN |
| ENUM | List of values | Status ENUM('Active','Inactive') |
ALTER TABLE
DROP TABLE
DML (Data Manipulation Language)
Basic Query Structure
FROM <tables>
[WHERE <condition>]
[GROUP BY <attributes>]
[HAVING <group condition>]
[ORDER BY <attributes> [ASC|DESC]]
SELECT - Projection
WHERE - Selection
JOIN Operations
RIGHT JOIN = "Keep everything from the right table"
INNER JOIN = "Keep only matches"
Aggregation Functions
GROUP BY & HAVING
ORDER BY
Nested Queries (Subqueries)
Set Operations
INSERT
UPDATE
DELETE
Views
๐ Functional Dependencies (FDs)
Definition
X โ Y means: If two tuples have the same X value, they must have the same Y value.
If t1[SSN] = t2[SSN], then t1[Name] = t2[Name]
SSN โ {Name, Address, Salary} (SSN determines multiple attributes)
{SSN, PNumber} โ Hours (combination determines Hours)
Types of Functional Dependencies
1. Full Dependency
Y depends on ALL of X (cannot remove any attribute from X).
Because: SSN alone doesn't determine Hours
And: PNumber alone doesn't determine Hours
2. Partial Dependency
Y depends on part of X (can remove some attributes from X).
Because: SSN โ Name (don't need PNumber)
3. Transitive Dependency
X โ Y and Y โ Z, so X โ Z indirectly.
DNumber โ DName (Department determines DeptName)
Therefore: SSN โ DName (transitive dependency)
Armstrong's Axioms
| Rule | Description | Example |
|---|---|---|
| Reflexivity | If Y โ X, then X โ Y | AB โ B (trivial) |
| Augmentation | If X โ Y, then XZ โ YZ | If A โ B, then AC โ BC |
| Transitivity | If X โ Y and Y โ Z, then X โ Z | If A โ B and B โ C, then A โ C |
| Union | If X โ Y and X โ Z, then X โ YZ | If A โ B and A โ C, then A โ BC |
| Decomposition | If X โ YZ, then X โ Y and X โ Z | If A โ BC, then A โ B and A โ C |
Finding Closure (X+)
Closure X+ = all attributes functionally determined by X.
FD1: A โ BC
FD2: CD โ E
FD3: E โ F
Find: (A)+
Start: (A)+ = {A}
FD1: A โ BC, so (A)+ = {A, B, C}
FD2: CD โ E, but we don't have D โ
No more changes
Result: (A)+ = {A, B, C}
Find: (AD)+
Start: (AD)+ = {A, D}
FD1: A โ BC, so (AD)+ = {A, B, C, D}
FD2: CD โ E, we have C and D โ, so (AD)+ = {A, B, C, D, E}
FD3: E โ F, we have E โ, so (AD)+ = {A, B, C, D, E, F}
Result: (AD)+ = {A, B, C, D, E, F} โ AD is a superkey!
โก Normalization & Normal Forms
Why Normalize?
- Minimize Redundancy: Don't store same data multiple times
- Prevent Update Anomalies: Avoid insertion, deletion, modification problems
- Improve Data Integrity: Maintain consistency
- Optimize Storage: Use less space
Update Anomalies
Sample Data:
(E1, John, P1, ProjectX, 10)
(E1, John, P2, ProjectY, 20)
(E2, Mary, P1, ProjectX, 15)
1. Update Anomaly:
Change P1 name to "ProjectZ" โ must update 2 rows!
2. Insert Anomaly:
Can't add new project without assigning employee
Can't add employee without assigning project
3. Delete Anomaly:
Delete E2 (only employee on P1) โ lose project P1 info!
First Normal Form (1NF)
Rule: All attributes must be atomic (no composite, no multivalued, no nested relations).
EMPLOYEE(SSN, Name, PhoneNumbers)
Where PhoneNumbers = {123, 456, 789}
Good (Fix 1):
EMPLOYEE(SSN, Name)
PHONE(SSN, PhoneNumber)
Good (Fix 2 - with redundancy):
EMPLOYEE(SSN, Name, Phone1, Phone2, Phone3)
Second Normal Form (2NF)
Rule: Must be in 1NF AND no partial dependencies (non-prime attributes must fully depend on primary key).
WORKS_ON(SSN, PNumber, Hours, EName, PName)
FDs:
{SSN, PNumber} โ Hours (full dependency โ)
SSN โ EName (partial dependency โ)
PNumber โ PName (partial dependency โ)
Good (Decompose):
WORKS_ON(SSN, PNumber, Hours)
EMPLOYEE(SSN, EName)
PROJECT(PNumber, PName)
Third Normal Form (3NF)
Rule: Must be in 2NF AND no transitive dependencies (non-prime attributes depend only on primary key, not on other non-prime attributes).
EMPLOYEE(SSN, Name, DNumber, DName, DMgrSSN)
FDs:
SSN โ DNumber (good)
SSN โ DName (transitive โ)
Because: SSN โ DNumber and DNumber โ DName
Good (Decompose):
EMPLOYEE(SSN, Name, DNumber)
DEPARTMENT(DNumber, DName, DMgrSSN)
Boyce-Codd Normal Form (BCNF)
Rule: For every FD X โ A, X must be a superkey.
Stronger than 3NF: Eliminates anomalies where prime attributes depend on non-keys.
TEACH(Student, Course, Instructor)
FDs:
{Student, Course} โ Instructor
Instructor โ Course (violates BCNF! Instructor not superkey)
Good (Decompose):
TEACHES(Instructor, Course)
ENROLLED(Student, Instructor)
Normal Forms Summary
| NF | Rule | Eliminates |
|---|---|---|
| 1NF | Atomic values only | Repeating groups, multivalued attributes |
| 2NF | 1NF + No partial dependencies | Redundancy from partial dependencies |
| 3NF | 2NF + No transitive dependencies | Redundancy from transitive dependencies |
| BCNF | Every determinant is a superkey | All anomalies based on FDs |
Normalization Algorithm
2. Check 2NF: Remove partial dependencies
For each partial dependency X โ A, create new relation R(X, A)
3. Check 3NF: Remove transitive dependencies
For each transitive dependency X โ Y โ Z, create R(Y, Z)
4. Check BCNF: For each FD X โ A where X not superkey
Decompose into R1(X, A) and R2(R - A)
5. Verify: Check lossless join and dependency preservation
๐ NoSQL & MongoDB
SQL vs NoSQL
| Aspect | SQL (RDBMS) | NoSQL (MongoDB) |
|---|---|---|
| Data Model | Tables with rows/columns | Documents (JSON-like) |
| Schema | Rigid, predefined | Flexible, dynamic |
| Relationships | Foreign keys, JOINs | Embedded documents, references |
| Scalability | Vertical (add more power) | Horizontal (add more servers) |
| ACID | Full support | Relaxed (eventual consistency) |
| Best For | Structured, transactional data | Unstructured, big data, rapid development |
MongoDB Terminology
| SQL | MongoDB |
|---|---|
| Database | Database |
| Table | Collection |
| Row/Tuple | Document |
| Column | Field |
| Primary Key | _id (auto-generated) |
| JOIN | Embedded documents/$lookup |
JSON & BSON
MongoDB Data Types
| Type | Description | Example |
|---|---|---|
| String | UTF-8 text | "John" |
| Integer | 32 or 64 bit | 42 |
| Double | Floating point | 3.14 |
| Boolean | true/false | true |
| Array | List of values | ["a", "b", "c"] |
| Object | Embedded document | {"x": 1, "y": 2} |
| Date | Timestamp | ISODate("2024-01-01") |
| Null | Null value | null |
| ObjectId | Unique identifier | ObjectId("507f1f77...") |
MongoDB CRUD Operations
Create (Insert)
Read (Query)
Update
Delete
MongoDB Query Operators
| Operator | Description | Example |
|---|---|---|
| $eq | Equal to | { age: { $eq: 20 } } |
| $ne | Not equal | { age: { $ne: 20 } } |
| $gt | Greater than | { age: { $gt: 20 } } |
| $gte | Greater than or equal | { age: { $gte: 20 } } |
| $lt | Less than | { age: { $lt: 20 } } |
| $lte | Less than or equal | { age: { $lte: 20 } } |
| $in | In array | { major: { $in: ["CS","SE"] } } |
| $nin | Not in array | { major: { $nin: ["CS"] } } |
| $and | Logical AND | { $and: [{...}, {...}] } |
| $or | Logical OR | { $or: [{...}, {...}] } |
| $not | Logical NOT | { age: { $not: { $gt: 20 } } } |
| $exists | Field exists | { email: { $exists: true } } |
Aggregation Pipeline
Embedding vs Referencing
Embedding (Denormalized)
Cons: Data duplication, harder to update
Referencing (Normalized)
Cons: Requires multiple queries or $lookup
๐ Database Security
Key Components
2. Encryption: Data protection at rest and in transit
3. Audit Trails: Logging all activities
4. Data Masking: Hide sensitive data
5. Backup & Recovery: Prevent data loss
6. Patch Management: Keep systems updated
7. Firewalls: Network-level protection
SQL Security Commands (DCL)
Database Users
| User Type | Role | Responsibilities |
|---|---|---|
| DBA | Administrator | Authorize access, monitor performance, backup/recovery |
| Database Designer | Architect | Define schema, constraints, relationships |
| End User | User | Query, update data through applications |
| Application Developer | Programmer | Build applications using database |
๐ System Catalog (Data Dictionary)
Definition: Metadata about the database stored in the database itself.
What's Stored in System Catalog
- Relation/table names
- Attribute names and data types
- Constraints (primary keys, foreign keys, NOT NULL, etc.)
- Views definitions
- Indexes and storage structures
- User privileges and security info
- Statistics for query optimization (tuple counts, value distributions)
๐๏ธ Database Architecture
Three-Schema Architecture
| Level | View | Description | Example |
|---|---|---|---|
| External | User View | Different views for different users | Students see grades, Faculty see all data |
| Conceptual/Logical | Community View | Overall logical structure (ER, tables) | STUDENT(ID, Name, GPA) |
| Internal/Physical | Storage View | How data is physically stored | B-trees, file organization, indexes |
Data Independence
Change internal schema without changing conceptual schema
Example: Change from B-tree to hash index โ applications unaffected
2. Logical Data Independence:
Change conceptual schema without changing external schemas
Example: Add new attribute to table โ views don't break
(Harder to achieve than physical!)
Client-Server Architectures
2-Tier Architecture
- Client: User interface + application logic
- Server: Database server (DBMS)
- Example: Desktop application connecting directly to database
3-Tier Architecture
- Presentation Tier: User interface (web browser, mobile app)
- Application Tier: Business logic (web server, API)
- Data Tier: Database server
- Advantages: Better security, scalability, maintainability
โก Quick Reference Tables
SQL vs MongoDB Commands
| Operation | SQL | MongoDB |
|---|---|---|
| Create DB | CREATE DATABASE db | use db |
| Create Table/Collection | CREATE TABLE student(...) | db.createCollection("student") |
| Insert | INSERT INTO student VALUES(...) | db.student.insertOne({...}) |
| Select All | SELECT * FROM student | db.student.find() |
| Where Clause | SELECT * FROM student WHERE age > 20 | db.student.find({age: {$gt: 20}}) |
| Update | UPDATE student SET age=21 WHERE id=1 | db.student.updateOne({id:1}, {$set:{age:21}}) |
| Delete | DELETE FROM student WHERE id=1 | db.student.deleteOne({id:1}) |
| Join | SELECT * FROM a JOIN b ON a.id=b.id | db.a.aggregate([{$lookup:{...}}]) |
| Group By | SELECT major, COUNT(*) FROM student GROUP BY major | db.student.aggregate([{$group:{_id:"$major", count:{$sum:1}}}]) |
Normal Forms Cheat Sheet
| Normal Form | Check For | How to Fix |
|---|---|---|
| 1NF | Multivalued or composite attributes | Create separate table or flatten |
| 2NF | Partial dependencies (non-prime โ part of key) | Move to separate table with partial key |
| 3NF | Transitive dependencies (non-prime โ non-prime) | Move to separate table with determinant |
| BCNF | Any FD where determinant isn't superkey | Decompose into R1(X,A) and R2(R-A) |
ER Diagram Symbols
| Symbol | Meaning | Example |
|---|---|---|
| Rectangle | Strong Entity | EMPLOYEE |
| Double Rectangle | Weak Entity | DEPENDENT |
| Oval | Attribute | Name, Age |
| Double Oval | Multivalued Attribute | {Phone_Numbers} |
| Dashed Oval | Derived Attribute | Age (from BirthDate) |
| Underline | Key Attribute | SSN |
| Dashed Underline | Partial Key | Dependent_Name |
| Diamond | Relationship | WORKS_FOR |
| Double Diamond | Identifying Relationship | DEPENDENTS_OF |
| Single Line | Partial Participation | Not all employees manage |
| Double Line | Total Participation | All employees work for a dept |
| 1, N, M | Cardinality Ratio | 1:N, M:N |
| (min, max) | Participation Constraint | (0,N), (1,1) |
๐ฏ Exam Tips & Tricks
Common Mistakes to Avoid
Always specify ON DELETE and ON UPDATE actions!
WHERE filters tuples BEFORE grouping
HAVING filters groups AFTER grouping
1:N โ Foreign key goes on the N side
M:N โ Create junction table with both keys
Check in order: 1NF โ 2NF โ 3NF โ BCNF
Don't skip steps!
COUNT(*) vs COUNT(DISTINCT column) are different!
Problem-Solving Strategies
1. Identify all nouns (potential entities)
2. Identify all verbs (potential relationships)
3. Determine attributes for each entity
4. Find keys (what uniquely identifies each entity?)
5. Determine cardinality (1:1, 1:N, M:N)
6. Check for weak entities (depend on others?)
1. List all FDs from the problem
2. Find all candidate keys using closure
3. Check 1NF (atomic values?)
4. Check 2NF (partial dependencies?)
5. Check 3NF (transitive dependencies?)
6. Check BCNF (all determinants superkeys?)
7. Decompose if needed
1. Understand what output is needed
2. Identify which tables are needed
3. Determine join conditions
4. Add WHERE filters
5. Add GROUP BY if aggregating
6. Add HAVING if filtering groups
7. Add ORDER BY if sorting needed
8. Test with sample data mentally
Time-Saving Tips
1. Eliminate obviously wrong answers first
2. Look for keywords (ALL, NONE, ALWAYS, NEVER often wrong)
3. Check for trick wording carefully
4. Use process of elimination
1. Draw ER diagram first (visualize!)
2. Map to relational step-by-step
3. Write down all constraints
4. Check your work by tracing sample data
Last-Minute Review Checklist
- โ Know all 4 ACID properties and examples
- โ Can draw and map ER diagrams (all 9 steps)
- โ Understand all key types (super, candidate, primary, foreign)
- โ Know cardinality ratios (1:1, 1:N, M:N) and where FK goes
- โ Can identify weak entities and their notation
- โ Understand EER concepts (specialization, generalization, categories)
- โ Know all 4 constraints on specialization (d/o, total/partial)
- โ Can write basic SQL queries (SELECT, FROM, WHERE, JOIN)
- โ Know difference between INNER/LEFT/RIGHT/FULL OUTER JOIN
- โ Understand aggregation functions (COUNT, SUM, AVG, MAX, MIN)
- โ Can use GROUP BY and HAVING correctly
- โ Know nested queries (IN, EXISTS, ANY, ALL)
- โ Understand functional dependencies (full, partial, transitive)
- โ Can find closure of attributes
- โ Know all normal forms (1NF, 2NF, 3NF, BCNF) and how to fix violations
- โ Can decompose relations properly
- โ Understand update anomalies (insert, delete, modify)
- โ Know MongoDB basic CRUD operations
- โ Understand embedding vs referencing in NoSQL
- โ Know database security concepts and DCL commands
๐ Advanced SQL Topics
Triggers
Automatically execute code when certain events occur.
Assertions
Global constraints that must always be true.
Transactions (TCL)
Indexes
Speed up query performance by creating fast lookup structures.
Window Functions (Advanced Analytics)
Common Table Expressions (CTEs)
๐ฎ Object-Oriented Databases (OODBMS)
Key Concepts
| Concept | Description | Example |
|---|---|---|
| Objects | Data stored as programming objects | Employee object with methods and attributes |
| Classes | Template for objects | Employee class defines structure |
| Inheritance | Classes inherit from parent classes | Manager inherits from Employee |
| Encapsulation | Data and methods bundled together | Employee.calculateSalary() method |
| Persistence | Objects survive program termination | Objects stored in database |
RDBMS vs OODBMS
| Aspect | RDBMS | OODBMS |
|---|---|---|
| Data Structure | Tables (rows & columns) | Objects with attributes & methods |
| Relationships | Foreign keys, JOINs | Direct object references |
| Query Language | SQL | OQL (Object Query Language) |
| Inheritance | Not supported | Native support |
| Complex Data Types | Difficult | Easy (arrays, nested objects) |
| Best For | Business transactions | CAD, multimedia, complex apps |
Customer {
customerID: String
name: String
orders: List<Order> // Direct reference!
}
Order {
orderID: String
customer: Customer // Direct reference!
amount: Float
}
In RDBMS:
Customer(CustomerID, Name)
Order(OrderID, CustomerID, Amount) -- Foreign key
โก Performance & Optimization Tips
Query Optimization
Especially for WHERE, JOIN, and ORDER BY clauses
Only select columns you need to reduce data transfer
Pagination improves performance
See query execution plan and identify bottlenecks
INNER JOIN is faster than OUTER JOIN when possible
Reduce data before grouping/joining
Sometimes breaking normal forms improves performance
INSERT many rows at once instead of multiple single inserts
When to Denormalize
- Read operations vastly outnumber writes
- Complex joins causing performance issues
- Data warehouse / reporting scenarios
- Real-time dashboards needing fast queries
๐ Final Study Strategies
The 24-Hour Before Exam Plan
โข Review ER diagrams and mapping (1 hour)
โข Practice SQL queries - write 10 different queries (1.5 hours)
โข Review normalization - work through 2 examples (30 min)
โข Review all memory hacks from this cheat sheet (30 min)
โข Practice finding FDs and closures (1 hour)
โข Review ACID properties with examples (30 min)
โข Quick MongoDB CRUD review (1 hour)
โข Review all formulas and definitions (1 hour)
โข Practice one complete database design problem (1 hour)
โข Light review of weak areas only
โข Read through this cheat sheet once
โข Get 8 hours of sleep!
โข DON'T cram new material
Active Recall Questions
โข What are the 4 ACID properties? Give examples.
โข Draw an ER diagram for a university database
โข What's the difference between 2NF and 3NF?
โข Where does the foreign key go in 1:N relationship?
โข Write SQL query to find employees earning above department average
โข What's the closure of {A,B} given FDs: AโC, BโD, CDโE?
โข How do you fix a partial dependency?
โข What's the difference between INNER JOIN and LEFT JOIN?
Common Exam Question Types
โ All entities (strong and weak)
โ All relationships with cardinality
โ All attributes (including keys)
โ Participation constraints
โ Apply all 9 mapping steps
โ Identify primary and foreign keys
โ Specify ON DELETE/UPDATE actions
โ Find all candidate keys
โ Check each normal form
โ Decompose if violations found
โ Verify lossless join
โ Select with conditions
โ Join multiple tables
โ Use aggregation and GROUP BY
โ Write nested subqueries
โ ACID properties
โ Referential integrity
โ Data independence
โ Update anomalies
๐ Master Formula & Definition Sheet
Key Definitions (Memorize These!)
Essential Formulas
(R1 โฉ R2) โ (R1 - R2) OR (R1 โฉ R2) โ (R2 - R1) must be in F+
๐ Final Exam Day Reminders
1. Read ALL questions first
2. Do easy questions first (build confidence!)
3. Budget time: divide total time by points
4. Leave hard questions for last
1. Draw diagrams for complex problems
2. Show your work (partial credit!)
3. Check for obvious mistakes (NULL in primary key?)
4. Use examples to verify your answer
5. If stuck, move on and come back
โ Did you underline all keys?
โ Did you specify foreign key constraints?
โ Did you check ALL normal forms?
โ Did you use correct JOIN syntax?
โ Did you handle NULL values properly?
โ Did you use GROUP BY with aggregates?
โ Did you put foreign key on correct side?
Remember: You've learned an entire semester of material. Trust your preparation, stay calm, and think through each problem logically. Database design is about understanding concepts and applying them systematically. You know this material!
Good Luck on Your Exam! ๐
Study smart, stay confident, and show what you know!
CS340 - Database Systems