Docsity

SQL & Database Management Systems (DBMS) Complete Exam Study Guide, Cheat Sheet of Database Management Systems (DBMS)

Toggle sidebar
bg1
COMPUTER SCIENCE EXAM & TECHNICAL INTERVIEW PREP • CS210 / CIS300 / DBMS
SQL & Database Management Systems: Complete
Exam Study Guide
Three-Schema Architecture, ER Modeling, Relational Algebra, Normalization (1NF–BCNF), ACID
Transactions, Concurrency Control & SQL Joins
1. Introduction to DBMS & Three-Schema Architecture
A
Database Management System (DBMS)
provides centralized data management, data independence,
ACID transaction guarantees, access security, and concurrent multi-user execution. In contrast, traditional
flat file systems suffer from data redundancy, isolation, update anomalies, and poor concurrency.
Architecture Level Core Purpose & Responsibility Data Independence Provided
External Schema
(View Level)
Tailors customized data views for specific end-
user roles or applications while hiding sensitive
or irrelevant columns.
Shielded from conceptual
changes via
Logical Data
Independence
.
Conceptual Schema
(Logical Level)
Defines the logical structure of the entire
database: entities, attributes, data types,
relationships, and integrity constraints.
Shielded from storage changes
via
Physical Data
Independence
.
Internal Schema
(Physical Level)
Describes low-level physical storage on disk: B+
tree indexes, hashing structures, block sizes, and
compression.
Allows index/storage tuning
without rewriting application
queries.
2. Entity-Relationship (ER) Modeling
Entity & Entity Set:
A distinguishable real-world object (e.g.,
Student
,
Course
). A
Weak Entity
lacks a
primary key of its own and depends on an identifying owner entity via a double-bordered relationship.
Attribute Classifications:
Simple vs. Composite (e.g., Full Name
→
First + Last), Single-valued vs.
Multi-valued (double oval), and Derived attributes (dashed oval, e.g., Age computed from Date of Birth).
Mapping Cardinality Ratios:
One-to-One (1:1), One-to-Many (1:N), and Many-to-Many (M:N). In
relational schema mapping, every M:N relationship requires a separate
junction (associative) table
containing foreign keys from both participating tables.
Participation Constraints:
Total Participation
(double line) requires every entity in the set to participate
in at least one relationship instance;
Partial Participation
(single line) permits zero participation.
3. Relational Model & Relational Algebra
Core Integrity Constraints
Domain Constraint:
Every attribute value must be atomic and drawn from its declared data type domain.
Entity Integrity Constraint:
No attribute belonging to a Primary Key may contain a
NULL
value.
Referential Integrity Constraint:
A Foreign Key value in a referencing table must either match an
existing Primary Key value in the referenced table or be wholly
NULL
.
SQL & Database Management Systems (DBMS) — Complete Exam Study Guide Page 1 of 4
pf3
pf4

Partial preview of the text

Download SQL & Database Management Systems (DBMS) Complete Exam Study Guide and more Cheat Sheet Database Management Systems (DBMS) in PDF only on Docsity!

COMPUTER SCIENCE EXAM & TECHNICAL INTERVIEW PREP • CS210 / CIS300 / DBMS

SQL & Database Management Systems: Complete

Exam Study Guide

Three-Schema Architecture, ER Modeling, Relational Algebra, Normalization (1NF–BCNF), ACID

Transactions, Concurrency Control & SQL Joins

1. Introduction to DBMS & Three-Schema Architecture

A Database Management System (DBMS) provides centralized data management, data independence,

ACID transaction guarantees, access security, and concurrent multi-user execution. In contrast, traditional

flat file systems suffer from data redundancy, isolation, update anomalies, and poor concurrency.

Architecture Level Core Purpose & Responsibility Data Independence Provided

External Schema (View Level)

Tailors customized data views for specific end- user roles or applications while hiding sensitive or irrelevant columns.

Shielded from conceptual changes via Logical Data Independence.

Conceptual Schema (Logical Level)

Defines the logical structure of the entire database: entities, attributes, data types, relationships, and integrity constraints.

Shielded from storage changes via Physical Data Independence.

Internal Schema (Physical Level)

Describes low-level physical storage on disk: B+ tree indexes, hashing structures, block sizes, and compression.

Allows index/storage tuning without rewriting application queries.

2. Entity-Relationship (ER) Modeling

Entity & Entity Set: A distinguishable real-world object (e.g., Student , Course ). A Weak Entity lacks a

primary key of its own and depends on an identifying owner entity via a double-bordered relationship.

Attribute Classifications: Simple vs. Composite (e.g., Full Name → First + Last), Single-valued vs.

Multi-valued (double oval), and Derived attributes (dashed oval, e.g., Age computed from Date of Birth).

Mapping Cardinality Ratios: One-to-One (1:1), One-to-Many (1:N), and Many-to-Many (M:N). In

relational schema mapping, every M:N relationship requires a separate junction (associative) table

containing foreign keys from both participating tables.

Participation Constraints: Total Participation (double line) requires every entity in the set to participate

in at least one relationship instance; Partial Participation (single line) permits zero participation.

3. Relational Model & Relational Algebra

Core Integrity Constraints

Domain Constraint: Every attribute value must be atomic and drawn from its declared data type domain.

Entity Integrity Constraint: No attribute belonging to a Primary Key may contain a NULL value.

Referential Integrity Constraint: A Foreign Key value in a referencing table must either match an

existing Primary Key value in the referenced table or be wholly NULL.

Operator Symbol Relational Algebra Definition & SQL Equivalent

Selection σp(R) Filters horizontal rows from relation R that satisfy predicate p (SQL: WHERE ).

Projection πA1,A2(R) Extracts vertical columns A 1 , A 2 and eliminates duplicate tuples (SQL: SELECT DISTINCT ).

Set Operations ∪ , ∩, − Union, Intersection, and Set Difference; requires both relations to be union-compatible (same arity and matching domains).

Cartesian Product R × S Pairs every tuple of R with every tuple of S (cardinality = |R| × |S|).

Natural Join R ⋈ S Combines tuples from R and S that share equal values on all common attribute names, removing duplicate columns.

4. Database Normalization (1NF to BCNF)

Normalization decomposes poorly structured tables to eliminate data redundancy and prevent insertion,

update, and deletion anomalies. A Functional Dependency (FD) X → Y states that attribute set X

uniquely determines attribute set Y.

Normal Form Formal Requirement Anomaly Eliminated / Test Rule

1NF (First)

All column domains contain only atomic (indivisible) single values; no repeating groups or nested tables.

Eliminates multi-valued attributes and non-flat records.

2NF

(Second)

Must be in 1NF AND every non-prime attribute is fully functionally dependent on the entire primary key.

Eliminates partial dependencies (only applies when the primary key is composite).

3NF (Third)

Must be in 2NF AND for every non-trivial FD X → Y , either X is a super key OR Y is a prime attribute.

Eliminates transitive dependencies between non-key attributes (e.g., StudentID → Zip → City ).

BCNF (Boyce-Codd)

For every non-trivial functional dependency X → Y , X must be a super key (no prime-attribute exception).

Eliminates all redundancy caused by overlapping candidate keys.

Exam Decomposition Rule: Lossless Join vs. Dependency Preservation

Every relational schema can be decomposed into 3NF with both a lossless join and dependency

preservation. Decomposition into BCNF always guarantees a lossless join , but may occasionally sacrifice

dependency preservation.

High-Frequency Exam SQL Queries

-- 1. Find the Second Highest Salary (Subquery Pattern) SELECT MAX(salary) AS SecondHighestSalary FROM Employee WHERE salary < (SELECT MAX(salary) FROM Employee);

-- 2. Aggregation with GROUP BY and HAVING Filter SELECT department_id, COUNT(*) AS emp_count, AVG(salary) AS avg_salary FROM Employee GROUP BY department_id HAVING AVG(salary) > 60000;

7. Solved University Exam Practice Problem

Question: Given relation R(A, B, C, D, E) with functional dependencies F = { A → BC, CD → E, B

→ D, E → A }, find all candidate keys for R.

Step 1 — Inspect Right-Hand Sides (RHS): Every attribute (A, B, C, D, E) appears on the RHS of at

least one FD, so no single attribute is automatically excluded from candidate keys. Test attribute

closures starting with single attributes on the left-hand side.

Step 2 — Compute Closure of A (A+):

Start with A+^ = {A}. Using A → BC , add B and C → {A, B, C}. Using B → D , add D → {A, B,

C, D}. Using CD → E , add E → {A, B, C, D, E}. Because A+^ = R , {A} is a candidate key.

Step 3 — Compute Closure of E (E+):

Start with E+^ = {E}. Using E → A , add A → {E, A}. Since A+^ determines all remaining attributes,

E+^ = {A, B, C, D, E}. Thus, {E} is also a candidate key.

Step 4 — Check Remaining Attributes: B+^ = {B, D} , C+^ = {C} , D+^ = {D} , and (CD)+^ = {C, D,

E, A, B} = R. Therefore, {CD} is also a minimal super key. Final Candidate Keys: {A}, {E}, and

{CD}.