






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!







1. Core ERD Components & Crow's Foot Notation
Entity: A person, place, object, event, or concept about which data is stored (represented as a rectangle; table in relational model).
Attribute Types:
Simple vs. Composite: Simple cannot be subdivided (Gender); composite can be subdivided (Address Street, City, PostalCode).
Single-Valued vs. Multivalued: Multivalued can hold multiple values for one entity instance (e.g., Phone_Numbers — must be resolved into a separate bridge/child table in 1NF).
Derived Attribute: Calculated from other stored attributes (e.g., Age derived from Date_of_Birth; not physically stored to save space and ensure accuracy).
Relationship Participation & Cardinality:
Cardinality: Expresses the minimum and maximum number of entity occurrences associated with one occurrence of the related entity (1:1, 1:M, M:N).
M:N Resolution: Relational databases cannot directly implement Many-to-Many (M:N) relationships. They must be decomposed into two 1:M relationships using a Composite (Bridge / Associative) Entity whose primary key consists of the foreign keys from both parent tables.
Weak Entity: Exists only when associated with another parent entity (existence-dependent) and has a primary key partially or totally derived from the parent entity (e.g., DEPENDENT linked to EMPLOYEE).
2. Enhanced Entity-Relationship (EER) Modeling
Specialization (Top-Down) vs. Generalization (Bottom-Up): Creating Supertype (parent) and Subtype (child) hierarchies (e.g., EMPLOYEE supertype PILOT, MECHANIC, ACCOUNTANT subtypes).
Subtype Discriminator: An attribute in the supertype table that determines which subtype an instance belongs to (e.g., Emp_Type = 'P').
Disjointness & Completeness Constraints:
Disjoint ( d ): An instance of the supertype can belong to only one subtype.
Overlapping ( o ): An instance of the supertype can belong to multiple subtypes simultaneously.
Partial Completeness (Single line): Not every supertype instance must belong to a subtype.
Total Completeness (Double line): Every supertype instance must belong to at least one subtype.
Normalization eliminates data redundancies and prevents insert, update, and delete anomalies.
PROJECT(Proj_ID, Proj_Name, Proj_Budget)
EMPLOYEE(Emp_ID, Emp_Name, Dept_Code, Dept_Name)
Step 2: Convert to 3NF (Remove Transitive Dependencies):
ASSIGNMENT(Proj_ID, Emp_ID, Hours_Worked)
PROJECT(Proj_ID, Proj_Name, Proj_Budget)
EMPLOYEE(Emp_ID, Emp_Name, Dept_Code) (where Dept_Code is FK)
DEPARTMENT(Dept_Code, Dept_Name)
1. High-Yield SQL Joins & Subqueries
INNER JOIN: Returns only rows with matching values in both tables.
LEFT OUTER JOIN: Returns all rows from the left table and matched rows from the right table (NULL if no match).
Correlated Subquery: Inner query executes once for each row processed by the outer query (used with EXISTS / NOT EXISTS).
-- Example: Find employees earning more than the average salary of their own department
SELECT e.Emp_ID, e.Emp_Name, e.Salary, e.Dept_Code
FROM EMPLOYEE e
WHERE e.Salary > (
SELECT AVG(e2.Salary)
FROM EMPLOYEE e
WHERE e2.Dept_Code = e.Dept_Code
);
2. Views, Stored Procedures & Triggers
Views ( CREATE VIEW ): Virtual tables based on a SELECT query. Used to restrict data access (security) and simplify complex joins. Updatable only if the view does not contain GROUP BY, DISTINCT, aggregate functions (SUM, AVG), or multi-table joins.
Triggers: Procedural SQL code automatically invoked by the DBMS before or after an INSERT, UPDATE, or DELETE event (used for auditing, enforcing complex business rules, and updating derived attributes).
3. Query Processing & Performance Tuning 1. Parsing: DBMS checks SQL syntax and validates object names/privileges. 1. Optimization: Query optimizer evaluates execution plans (using table statistics, index availability, and I/O cost) to choose the lowest-cost path. 1. Execution: DBMS executes the chosen plan and fetches rows.
Indexing Best Practices: Create indexes on Primary Keys , Foreign Keys , and columns frequently used in WHERE, JOIN, ORDER BY, and GROUP BY clauses. Avoid over-indexing tables with heavy INSERT/UPDATE/DELETE workloads because every write operation must also update all associated indexes.
1. The ACID Properties of Transactions
A – Atomicity: All operations within a transaction succeed (COMMIT) or none take effect (ROLLBACK). "All-or-nothing."
C – Consistency: A transaction takes the database from one valid, consistent state to another, preserving all integrity constraints.
I – Isolation: Concurrent transactions execute independently without interfering with one another's intermediate states.
D – Durability: Once a transaction is committed, its changes are permanently saved to non- volatile storage, even after a system crash.
2. Concurrency Control Problems (Without Locking) 1. Lost Update: Two concurrent transactions read and update the same data item; the second update overwrites the first update.
Data Replication: Storing copies of data fragments at multiple sites (improves read speed and fault tolerance, but increases update overhead).
Two-Phase Commit (2PC) Protocol: Ensures atomicity across distributed nodes:
OLTP vs. OLAP: OLTP handles real-time daily transactions (highly normalized, 3NF); OLAP supports analytical reporting and decision-making (denormalized, Star/Snowflake schema).
Star Schema Components:
Fact Table: Central table containing numeric business metrics/facts (e.g., Sales_Amount, Units_Sold) and composite foreign keys linking to dimensions.
Dimension Tables: Surrounding tables describing business context (e.g., DIM_TIME, DIM_PRODUCT, DIM_CUSTOMER, DIM_STORE).
Section A: Multiple-Choice Questions (10 Questions)
1. Which normal form eliminates transitive dependencies among non-key attributes? A. 1NF B. 2NF C. 3NF D. 4NF
Answer: C — Third Normal Form (3NF) requires the relation to be in 2NF with no non-key attribute functionally determining another non-key attribute.
2. Which ACID property ensures that partial updates from an aborted transaction are never saved to the database? A. Isolation B. Durability C. Atomicity D. Consistency
Answer: C — Atomicity enforces the "all-or-nothing" rule via COMMIT and ROLLBACK.
3. Transaction T2 reads a record updated by T1 before T1 executes a ROLLBACK. What concurrency anomaly has occurred? A. Lost update B. Dirty read (uncommitted data) C. Deadlock
D. Phantom read
Answer: B — Reading uncommitted changes that are subsequently rolled back is a dirty read.
4. In an EER diagram, a double line connecting a supertype to a specialization circle with the letter d inside indicates: A. Partial, overlapping specialization B. Total, disjoint specialization C. Partial, disjoint specialization D. Total, overlapping specialization
Answer: B — Double line = total completeness (every supertype instance must belong to a subtype); d = disjoint (at most one subtype).
5. Which protocol guarantees distributed transaction atomicity across multiple database servers? A. Two-Phase Locking (2PL) B. Two-Phase Commit (2PC) C. Star Schema Aggregation D. Vertical Fragmentation
Answer: B — The Two-Phase Commit (2PC) protocol coordinates PREPARE and COMMIT/ABORT phases across distributed sites.
6. In a data warehouse Star Schema, which table stores quantitative business metrics and foreign keys to descriptive tables? A. Dimension table B. Bridge table C. Fact table D. Lookup table
Answer: C — The central Fact table stores numeric measures and foreign keys referencing each Dimension table.
7. Which level of lock granularity provides the highest degree of concurrency in a multi-user OLTP system? A. Database-level lock B. Table-level lock C. Page-level lock D. Row-level lock
Answer: D — Row-level locking locks only the specific tuple being modified, allowing other users to access different rows in the same table simultaneously.
8. What is the main disadvantage of creating too many indexes on a heavily updated transactional table? A. SELECT queries become slower B. Primary key constraints are disabled C. INSERT, UPDATE, and DELETE operations slow down due to index maintenance overhead D. Normalization rules are violated
Answer: C — Every data modification requires the DBMS to update every index defined on that table.
9. Splitting a CUSTOMER table across regional servers so that Gauteng customers are stored in Johannesburg and Western Cape customers are stored in Cape Town is an example of: A.
Balance Comparison: The expected final balance after depositing R500 and withdrawing R200 is R1,300. However, because read the initial R1,000 before wrote R1,500, 's write overwrote 's deposit, leaving an incorrect final balance of R800 ('s update is lost).
Prevention via Locking: Using Exclusive Locks ( X-lock ) under Two-Phase Locking (2PL), acquires an X-lock on Bal before reading/updating it. is forced to wait until writes R1,500 and commits (releasing the lock). then reads R1,500, subtracts R200, and writes the correct balance of R1,.
Question 2: Database Recovery – Deferred vs. Immediate Update (6 Marks) Compare Deferred Update and Immediate Update recovery techniques using the transaction log following a power failure.
Model Answer:
Deferred Update (No-Undo / Redo): Database modifications are written only to the transaction log during execution and are not applied to the physical disk until the transaction reaches its COMMIT point. If a crash occurs before COMMIT, no UNDO is needed because the disk was never altered; committed transactions are REDOne from the log.
Immediate Update (Undo / Redo): Modifications are written directly to the physical database buffers/disk before the transaction commits (after writing old and new values to the Write- Ahead Log). Upon recovery from a crash, uncommitted transactions must be UNDONE (restoring old values), while committed transactions are REDONE (reapplying new values).