Relational Model
This chapter develops the mathematical and logical foundation of relational databases: relations, schemas, dependencies, normalization, integrity, and relational operations.
2.1 Relational Data Model
Introduction / Definition
The relational data model represents data as relations, usually shown as tables. A relation contains tuples (rows) and attributes (columns). Each attribute has a domain of permitted values. Keys identify tuples and foreign keys connect related relations.
Syntax / Structure
R(A1, A2, ..., An)
Degree = number of attributes
Cardinality = number of tuples
Detailed Explanation
A relation STUDENT(Student_ID, Name, Marks) has degree 3. If it contains 100 rows, its cardinality is 100. A primary key uniquely identifies each tuple.
Example
STUDENT
101 | Asha | 86
102 | Ravi | 79
Output / Result
Degree = 3; cardinality of the displayed instance = 2.
Important Points / Notes
- Attributes are columns.
- Tuples are rows.
- Primary keys identify rows.
- Foreign keys represent references.
Mini Practice Question
For EMPLOYEE(Emp_ID, Name, Salary, Dept_ID), what is its degree?
2.2 Database Schema Design
Introduction / Definition
Schema design defines tables, attributes, keys, relationships, and constraints so the database accurately represents requirements. Good design reduces redundancy and update anomalies. Designers typically move from requirements to conceptual modeling, relational design, and then physical optimization.
Syntax / Structure
TABLE(Attribute1, Attribute2, ...)
PRIMARY KEY(...)
FOREIGN KEY(...) REFERENCES ...
Detailed Explanation
For a college, Student and Course are separate entities. Enrollment represents their many-to-many relationship. This prevents storing an unlimited list of courses in one Student row.
Example
STUDENT(Student_ID PK, Name)
COURSE(Course_ID PK, Title)
ENROLLMENT(Student_ID FK, Course_ID FK, Semester)
Output / Result
Each student and course is stored once, while Enrollment stores the relationship.
Important Points / Notes
- Identify entities and relationships.
- Choose suitable primary keys.
- Use foreign keys for relationships.
- Keep attributes atomic.
- Validate against real requirements.
Mini Practice Question
Design Student, Course, and Enrollment tables.
2.3 Normalization Theory
Introduction / Definition
Normalization organizes relations to reduce redundancy and undesirable update anomalies. It uses dependencies to decompose relations into smaller related relations. Important forms include 1NF, 2NF, 3NF, BCNF, 4NF, and 5NF. The goal is a sound representation rather than simply creating many tables.
Syntax / Structure
1NF: atomic values
2NF: 1NF + no partial dependency
3NF: 2NF + no problematic transitive dependency
BCNF: every determinant is a superkey
Detailed Explanation
If ENROLLMENT(Student_ID, Course_ID, Student_Name, Course_Name, Grade) has composite key (Student_ID, Course_ID), Student_Name depends only on Student_ID and Course_Name only on Course_ID. Decomposition removes these partial dependencies.
Example
Before: ENROLLMENT(Student_ID, Course_ID, Student_Name, Course_Name, Grade)
After: STUDENT(Student_ID, Student_Name)
COURSE(Course_ID, Course_Name)
ENROLLMENT(Student_ID, Course_ID, Grade)
Output / Result
Student and course facts are stored once, reducing update anomalies.
Important Points / Notes
- Normalization is dependency-based.
- Lossless decomposition is desirable.
- Dependency preservation is desirable.
- Denormalization may later be used for measured performance needs.
Mini Practice Question
Which normal form removes partial dependency on a composite key?
2.4 Functional Dependencies
Introduction / Definition
A functional dependency (FD) expresses a rule about how attributes determine other attributes. X → Y means that if two tuples agree on X, they must agree on Y. X is the determinant. Functional dependencies help identify keys and guide normalization.
Syntax / Structure
X → Y
If t1[X] = t2[X], then t1[Y] = t2[Y].
Detailed Explanation
If Student_ID uniquely identifies a student, Student_ID determines Name, DateOfBirth, and Department_ID. Department_ID normally does not determine Student_ID because many students may belong to one department.
Example
Student_ID → Name
Student_ID → DateOfBirth
Student_ID → Department_ID
Output / Result
Knowing Student_ID determines the corresponding values for those attributes.
Important Points / Notes
- FDs are semantic rules.
- They help identify candidate keys.
- Trivial FD: X → Y when Y ⊆ X.
- Armstrong's axioms can be used to infer dependencies.
Mini Practice Question
If A → B and B → C, what dependency follows by transitivity?
2.5 Higher Normal Forms
Introduction / Definition
Higher normal forms refine normalization beyond 3NF. BCNF requires every determinant of a non-trivial functional dependency to be a superkey. 4NF handles non-trivial multivalued dependencies. 5NF handles certain join dependencies. These forms are useful for complex schemas where lower normal forms leave redundancy.
Syntax / Structure
BCNF: X → Y ⇒ X is a superkey
4NF: X ↠ Y ⇒ X is a superkey for a non-trivial MVD
Detailed Explanation
If a student's hobbies and languages are independent multi-valued facts, storing every hobby-language combination creates unnecessary combinations. Separate relations avoid this redundancy.
Example
STUDENT_HOBBY(Student, Hobby)
STUDENT_LANGUAGE(Student, Language)
Output / Result
Independent multi-valued facts are stored separately.
Important Points / Notes
- BCNF is stricter than 3NF.
- 4NF focuses on multivalued dependencies.
- 5NF concerns join dependencies.
- Apply higher forms when dependencies justify them.
Mini Practice Question
Why should independent hobbies and languages often be stored separately?
2.6 Integrity Rules
Introduction / Definition
Integrity rules keep database values valid and relationships consistent. Domain integrity restricts values to valid domains. Entity integrity requires primary keys to be non-NULL. Referential integrity requires foreign keys to refer to existing keys when a reference is required.
Syntax / Structure
PRIMARY KEY
FOREIGN KEY ... REFERENCES ...
NOT NULL
UNIQUE
CHECK(condition)
Detailed Explanation
Constraints allow the DBMS to reject invalid data automatically. For example, marks can be restricted to 0–100 and Enrollment.Student_ID can be required to reference an existing Student.
Example
CREATE TABLE Student(
Student_ID INT PRIMARY KEY,
Name VARCHAR(50) NOT NULL,
Marks INT CHECK (Marks BETWEEN 0 AND 100)
);
Output / Result
Invalid marks or NULL primary keys are rejected by the DBMS.
Important Points / Notes
- Constraints improve data quality.
- Primary keys uniquely identify rows.
- Foreign keys maintain references.
- CHECK can enforce ranges and business rules.
Mini Practice Question
Write one integrity constraint for Employee Salary.
2.7 Relational Operators
Introduction / Definition
Relational operators manipulate relations and return relations. Fundamental operators include selection, projection, union, difference, Cartesian product, and rename. Join is a very important derived operation. Relational algebra gives a formal foundation for database query processing.
Syntax / Structure
σ_condition(R)
π_attributes(R)
R ∪ S
R − S
R × S
R ⋈_condition S
Detailed Explanation
Selection filters rows, while projection chooses columns. Join combines related tuples. Operators can be composed to express complex queries.
Example
π_Name(σ_Marks > 80(STUDENT))
Output / Result
The result contains names of students whose marks exceed 80.
Important Points / Notes
- Selection = rows.
- Projection = columns.
- Union requires compatible schemas.
- Cartesian product can be large.
- Joins combine related data.
Mini Practice Question
Write relational algebra for names of students with Marks > 75.