Structure of a Relational Table (Relation)
Structure of a Relational Table (Relation)
Formal Relational Term
Relation
Tuple
Attribute
Domain
Tuple
Attribute
Domain
Common Commercial Term
Table
Row / Record
Column / Field
Allowed Values / Data Type
Row / Record
Column / Field
Allowed Values / Data Type
Explanation
- A row represents one tuple and a column represents one attribute.
- The attribute's domain limits the kind of value that can occupy a cell.
Hierarchy and Filtering of Keys
Hierarchy and Filtering of Keys
Super Keys
All combinations that guarantee uniqueness
All combinations that guarantee uniqueness
➔ Minimal Subset ➔
Candidate Keys
Minimal Super Keys with zero redundant fields
Minimal Super Keys with zero redundant fields
➔ DBA Selection ➔
Primary Key
Chosen main identifier
Chosen main identifier
➔ Alternate Keys
Remaining candidates
Remaining candidates
Explanation
- Any set of attributes that uniquely identifies a row is a superkey.
- A minimal superkey is a candidate key, and one candidate becomes the primary key.
The Three Pillars of Relational Integrity
The Three Pillars of Relational Integrity
1. Domain Integrity
Every value in a column must be valid according to its defined data type, format, and range.
2. Entity Integrity
No primary key column can ever contain a NULL value or duplicate value.
3. Referential Integrity
Every foreign key value must either match an existing primary key in the parent table or be NULL.
Explanation
- Domain rules constrain values and entity integrity requires an identifiable row.
- Referential integrity checks the links between rows.
Referential Integrity Link Between Tables
Referential Integrity Link Between Tables
Parent Table: DEPARTMENT
Dept_ID = 10 (Computer Science)
Dept_ID = 10 (Computer Science)
➔ Referenced By ➔
Child Table: STUDENT
Roll_No: 101, Name: 'Aman', Dept_ID: 10
Roll_No: 101, Name: 'Aman', Dept_ID: 10
Explanation
- A foreign key in one table refers to a candidate key in another or the same table.
- A non-null reference must match an allowed existing key.
The Three Dangerous Database Anomalies
The Three Dangerous Database Anomalies
1. Insertion Anomaly
You cannot add new data without adding completely unrelated dummy or NULL data.
2. Deletion Anomaly
Deleting one piece of information accidentally destroys completely unrelated vital records!
3. Update (Modification) Anomaly
Changing a single value requires modifying hundreds of duplicate rows; missing one causes inconsistency.
Explanation
- Repeating facts across many rows makes updates easy to miss.
- It can also force the insertion of unrelated details or erase a fact when a row is deleted.
The Normalization Progression
The Normalization Progression
1NF
Atomic values only (No repeating groups)
Atomic values only (No repeating groups)
➔ 2NF
1NF + No Partial Dependencies
1NF + No Partial Dependencies
➔ 3NF
2NF + No Transitive Dependencies
2NF + No Transitive Dependencies
➔ BCNF
Every determinant is a Super Key
Every determinant is a Super Key
Explanation
- First normal form sets the starting structure and second normal form removes partial dependencies.
- Third normal form addresses problematic transitive dependencies and BCNF requires each nontrivial determinant to be a superkey.
Dependencies in higher normal forms
Dependencies in higher normal forms
4NF
Separate independent multivalued facts
5NF
Remove redundancy due to join dependencies
DKNF
All constraints follow from domains and keys
Explanation
- Fourth normal form separates independent multivalued facts.
- Fifth normal form addresses join dependencies, while DKNF requires constraints to follow from domains and keys.
Relationship Transformation Strategy
Relationship Transformation Strategy
One-to-One (1:1)
Foreign Key approach: Place the PK of one entity as FK in the other (preferably total participation side).
One-to-Many (1:N)
Place the PK of the "1" side as a Foreign Key in the "N" (Many) side table.
Many-to-Many (M:N)
Create a separate Junction / Cross-Reference Table containing the PKs of both entities.
Explanation
- A one-to-many relationship commonly puts the foreign key on the many side.
- A many-to-many relationship needs a linking relation containing both keys.