←Back to Subject
Notes
Notes
Study material and explanations
Diagrams
Diagrams
Visualize concepts easily
Mnemonics
Mnemonics
Tricks to remember faster
One Night Prep
One Night Prep
Short and focused revision
Revision
Revision
Quick summary and key points
Important Questions
Important Questions
Practice most relevant questions
Revision

DBMS · Unit 2 Revision

Quick summary and key points for Unit 2

The Relational Data Model: Relations, Tuples, Domains, and Keys

Overview: Two columns may each uniquely identify a student, for example a roll number and an institute email.

What is the Relational Data Model?

  • Introduced by **Dr.

Fundamental Terminology of the Relational Model

  • In academic computer science (DAVV examinations), standard database concepts have specific formal mathematical names:
  • Formal Relational Term Relation Tuple Attribute Domain
  • Common Commercial Term Table Row / Record Column / Field Allowed Values / Data Type
  • Detailed Definitions: Relation (Table): A collection of rows and columns containing data about a specific entity (e.g., STUDENT relation).
  • Tuple (Row / Record): A single horizontal row in a relation representing one specific real-world object (e.g., records for student “Rahul”).
  • Attribute (Column / Field): A named vertical column representing a specific property of the relation (e.g., Roll_No, Student_Name, Marks).
  • Domain: The pool of legal, atomic values from which an attribute draws its values (e.g., the domain of Age is positive integers…
  • Degree of a Relation: The total number of attributes (columns) in a table.

View diagram · Structure of a Relational Table (Relation)

Null Values in Relational Databases

  • What does NULL mean in a database table?
  • NULL is NOT zero (0) .
  • NULL is NOT an empty text string (“”) or blank space .
  • NULL represents MISSING, UNKNOWN, or NOT APPLICABLE data .
  • Real-World Scenarios of NULL: Unknown Value: A new patient is admitted to a hospital unconscious; their Blood_Group is currently NULL until a blood test is conducted.
  • Not Applicable Value: A student lives in a hostel; their Home_Landline_Number attribute is NULL because they do not have a landline phone.

All Types of Keys in DBMS

  • A Key is an attribute or a set of attributes used to uniquely identify any row (tuple) in a relation and establish links between different…
  • A. Super Key (SK): Any set of attributes that uniquely identifies a row in a relation.
  • A super key may contain extra, redundant attributes.
  • Example in STUDENT(Roll_No, Email, Phone, Name, City):
  • {Roll_No} is a super key.
  • {Roll_No, Name} is also a super key (even though Name is redundant!).
  • {Roll_No, Email, City} is also a super key.
  • B. Candidate Key (CK): A minimal Super Key with no unnecessary or redundant attributes.

View diagram · Hierarchy and Filtering of Keys

Relational Integrity Constraints: Entity, Referential, and Domain Rules

Overview: A duplicate roll number violates a uniqueness rule.

What are Integrity Constraints?

  • In a database, Integrity means Accuracy, Consistency, and Correctness of data.

The Three Fundamental Relational Integrity Constraints

  • The relational model enforces three primary categories of integrity constraints:
  • 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.

View diagram · The Three Pillars of Relational Integrity

Deep Dive: Domain Integrity Constraints

  • Ensures that every column contains valid, atomic values conforming to its defined Data Domain.
  • Checks Enforced:
  • Data Type Check: Trying to enter "Rahul" into an Age column (defined as INT) is immediately blocked by the database engine.
  • Range Check: Restricting values using CHECK constraints (e.g., CHECK (Marks >= 0 AND Marks <= 100)).
  • Format / Pattern Check: Ensuring email addresses contain an @ symbol or phone numbers contain exactly 10 digits.
  • Default Value Check: Assigning automatic fallback values when a user leaves a field blank (e.g., DEFAULT 'Pending').

Deep Dive: Entity Integrity Constraint

  • Formal Rule: No attribute that participates in the primary key of a base relation can accept a NULL value.
  • Why is this necessary?
  • The Primary Key is the sole hardware identifier used to distinguish individual real-world objects in a relation.
  • If a primary key attribute were NULL, the DBMS would have no way to locate, distinguish, or link that specific row!
  • Example:
  • In table STUDENT(Roll_No, Name, Email) where Roll_No is the primary key:
  • Inserting INSERT INTO STUDENT VALUES (NULL, 'Priya', 'priya@gmail.com'); will immediately throw an Entity Integrity Violation Error.

Deep Dive: Referential Integrity Constraint (Foreign Key Rules)

  • Formal Rule: *If a foreign key FK exists in relation R1 referencing primary key PK of relation R2, then for every tuple in R1, the value…
  • Prevents Orphan Records (e.g., a student record assigned to a department Dept_ID = 99 when no department 99 exists!).
  • What Happens When a Parent Record is Deleted or Updated?: Suppose the college decides to delete DEPARTMENT 10.
  • 1. ON DELETE RESTRICT (or NO ACTION): Rejects the deletion! The DBMS blocks the user from deleting Department 10 as long as student rows exist.
  • 2. ON DELETE CASCADE: Cascades the deletion! Automatically deletes Department 10 AND automatically deletes all students…
  • 3. ON DELETE SET NULL: Deletes Department 10, but automatically updates the Dept_ID of affected students to NULL.
  • 4. ON DELETE SET DEFAULT: Deletes Department 10, but automatically sets affected students to a predefined fallback department (e.g.,…

View diagram · Referential Integrity Link Between Tables

Summary Table of Integrity Constraints

  • Domain Integrity: Columns / Attributes
  • Entity Integrity: Primary Keys
  • Referential Integrity: Foreign Keys
  • Key Constraint: Candidate Keys

Functional Dependencies, Armstrong’s Axioms, and Normalization Basics

Overview: Suppose each roll number belongs to one student.

What is Normalization and Why Do We Need It?

  • When designing a database, beginners often make the mistake of dumping all data into one single giant table.

The Three Update Anomalies

  • Consider an unnormalized table STUDENT_COURSE_FACULTY:
  • Practical Examples of the Anomalies: Insertion Anomaly: A new faculty member joins the college, but has not been assigned any students yet.
  • Deletion Anomaly: Student Roll_No 105 is the only student enrolled in “Cloud Computing”.
  • Modification Anomaly: Faculty member *“Dr.

View diagram · The Three Dangerous Database Anomalies

Functional Dependency (FD)

  • A Functional Dependency (FD) is a constraint between two sets of attributes in a relation.
  • Formal Definition: Given a relation R, an attribute Y is functionally dependent on attribute X (written as X → Y, read as *“X functionally…
  • Whenever two tuples have the same value for X, they MUST have the exact same value for Y.
  • Here, X is called the Determinant and Y is called the Dependent.
  • Real-World Examples: Roll_No → Student_Name: If two rows have the same Roll_No, they must have the same Student_Name (A roll number uniquely determines a…
  • Aadhar_No → {Name, DOB, Address}: An Aadhar number uniquely identifies all personal details.
  • ISBN → Book_Title: A book’s ISBN uniquely determines its title.
  • {Course_ID, Semester} → Syllabus: A course ID and semester together determine the exact syllabus.

Types of Functional Dependencies

  • Trivial Functional Dependency:
  • An FD X → Y is trivial if Y is a subset of X (Y ⊆ X).
  • Example: {Roll_No, Name} → Roll_No (Always guaranteed to be true by definition!).
  • Non-Trivial Functional Dependency:
  • An FD X → Y is non-trivial if Y is not a subset of X (Y ⊄ X).
  • Example: Roll_No → Name.
  • Completely Non-Trivial FD:
  • X ∩ Y = ∅ (They share zero common attributes).

Armstrong’s Axioms (Inference Rules for FDs)

  • Formulated by William W.
  • The Primary Axioms: Axiom of Reflexivity:
  • If Y ⊆ X, then X → Y.
  • Example: {Roll_No, Name} → Name.
  • Axiom of Augmentation:
  • If X → Y, then XZ → YZ for any attribute set Z.
  • Example: If Roll_No → Name, then {Roll_No, Dept_ID} → {Name, Dept_ID}.
  • Axiom of Transitivity:

Attribute Closure and Finding Candidate Keys

  • The Attribute Closure of a set of attributes X (written as X⁺) is the set of all attributes that can be functionally determined by X…
  • Algorithm to Calculate Closure (X⁺): Initialize X⁺ = X.
  • For every given FD A → B:
  • If A ⊆ X⁺, then add B to X⁺ (X⁺ = X⁺ ∪ B).
  • Repeat step 2 until no new attributes can be added.
  • Practical Exam Example: Given Relation R(A, B, C, D, E) with FDs:

Database Normal Forms: 1NF, 2NF, 3NF, and BCNF Explained

Overview: In a marks table keyed by student and paper, the student’s name depends on only part of the key.

Overview: The Normalization Ladder

  • Normalization is organized into hierarchical levels called Normal Forms.

View diagram · The Normalization Progression

First Normal Form (1NF)

  • Rule: *A relation is in 1NF if and only if all attribute values are Atomic (indivisible single values), and there are no…
  • 101: Aman
  • 102: Priya
  • The cell 9826011111, 9425022222 contains multiple values.
  • 101: Aman
  • 101: Aman
  • 102: Priya
  • Every cell now holds strictly one single atomic value.

Second Normal Form (2NF)

  • Rule: A relation is in 2NF if and only if:
  • It is already in 1NF.
  • There are NO Partial Functional Dependencies (Every non-prime attribute must be fully functionally dependent on the primary key).
  • Prime Attribute: An attribute that is part of any Candidate Key.
  • Non-Prime Attribute: An attribute that is NOT part of any Candidate Key.
  • Partial Dependency: When a non-prime attribute depends on only a part of a composite candidate key.
  • Candidate Key: {Emp_ID, Project_ID} (Composite Key).
  • Dependencies:

Third Normal Form (3NF)

  • Rule: A relation is in 3NF if and only if:
  • It is already in 2NF.
  • There are NO Transitive Dependencies for non-prime attributes.
  • Formal Mathematical Condition for 3NF: For every non-trivial functional dependency X → Y:
  • Either X is a Super Key, OR
  • Y is a Prime Attribute (part of a candidate key).
  • Candidate Key: Roll_No.
  • Dependencies:

Boyce-Codd Normal Form (BCNF / 3.5 NF)

  • Developed by Raymond F.
  • Rule: A relation is in BCNF if and only if for every non-trivial functional dependency X → Y, X MUST BE A SUPER KEY.
  • Notice that BCNF removes the second lenient loophole of 3NF (“Y is a prime attribute”).
  • In BCNF, the left-hand determinant X must always be a Super Key, with zero exceptions!
  • Classic Exam Scenario: Consider relation STUDENT_COUNSELOR(Student, Subject, Counselor):
  • Rules:
  • A student can choose multiple subjects.
  • For each subject, multiple counselors exist, but each counselor teaches only one subject (Counselor → Subject).

Summary Cheat Sheet of Normal Forms

  • 1NF: Atomic values only
  • 2NF: In 1NF + No partial dependencies
  • 3NF: In 2NF + No transitive dependencies
  • BCNF: In 3NF + Every determinant X is a Super Key

Higher Normal Forms: 4NF, 5NF (Project-Join), and Domain/Key Normal Form (DKNF)

Overview: If a student has two independent hobbies and speaks three languages, one combined table needs six pairs.

Introduction: Why Do We Need Higher Normal Forms?

  • While Boyce-Codd Normal Form (BCNF) eliminates all anomalies based on Functional Dependencies (FDs), some tables still experience severe…
  • Fourth Normal Form (4NF): Eliminates Multi-Valued Dependencies (MVD).
  • Fifth Normal Form (5NF / PJNF): Eliminates Join Dependencies.
  • Domain/Key Normal Form (DKNF): The ultimate theoretical ideal of database normalization.

Fourth Normal Form (4NF) & Multi-Valued Dependencies

  • What is a Multi-Valued Dependency (MVD)?: A Multi-Valued Dependency (written as X ↠ Y, read as “X multidetermines Y”) exists in a relation R when for a single…
  • Rahul: Cricket
  • Rahul: Cricket
  • Rahul: Music
  • Rahul: Music
  • Notice that Hobby and Language have zero logical connection to each other!
  • Yet, because both are multivalued attributes of Rahul, the database is forced to store 4 separate rows (Cartesian Product of hobbies…
  • If Rahul picks up a 3rd hobby (“Painting”), we must insert 2 new rows for Hindi and English!

Fifth Normal Form (5NF / Project-Join Normal Form - PJNF)

  • What is a Join Dependency (JD)?: A relation R has a Join Dependency (written as `*(R1, R2, R3, …
  • Definition of 5NF: A relation is in 5NF (PJNF) if and only if:
  • It is already in 4NF.
  • Every join dependency in the relation is implied by the Candidate Keys of the relation.
  • Real-World Example (The Agent-Company-Product Scenario): Suppose an enterprise records which Agent represents which Company to sell which Product:
  • Table R(Agent, Company, Product) has a composite key of all three fields.
  • But there exists a business constraint:
  • If Agent A represents Company C,

Domain/Key Normal Form (DKNF)

  • Introduced by Ronald Fagin in 1981, Domain/Key Normal Form (DKNF) represents the highest theoretical peak of relational normalization.
  • Definition of DKNF: *A relation is in DKNF if every constraint on the relation is a logical consequence of the definition of Domains and…
  • Domain Constraint: Values for an attribute belong to its legal, allowed domain (e.g., Salary > 0, Age between 18 and 65).
  • Key Constraint: Uniqueness enforced by Candidate Keys.
  • If a database design is in DKNF, it is impossible to have any insertion, deletion, or update anomalies whatsoever!
  • Practical Note: DKNF is an idealized theoretical goal.

Comprehensive Comparison of All Normal Forms

  • 1NF: Atomic attribute values; no repeating groups
  • 2NF: In 1NF + No partial functional dependencies
  • 3NF: In 2NF + No transitive dependencies
  • BCNF: In 3NF + Every determinant X is a Super Key
  • 4NF: In BCNF + No non-trivial Multi-Valued Dependencies (MVD)
  • 5NF (PJNF): In 4NF + No Join Dependencies not implied by keys
  • 4NF Separate independent multivalued facts
  • 5NF Remove redundancy due to join dependencies

View diagram · Dependencies in higher normal forms

Transforming Conceptual ER/EER Models to Relational Tables

Overview: Students attend many courses and a course has many students.

Introduction: From Blueprint to Physical Database

  • Designing an Entity-Relationship (ER) or Enhanced ER (EER) diagram is only half the battle.

Mapping Regular (Strong) Entity Sets and Attributes

  • Rule 1: Regular Entity Sets: For each strong entity set E, create a new relation R that includes all simple attributes of E.
  • Choose one of the key attributes of E as the Primary Key of R.
  • Example: Entity STUDENT(Roll_No, Name, DOB, Gender) becomes table:
  • Rule 2: Composite Attributes: Do not create a column for the composite attribute itself .
  • Instead, flatten the composite attribute by including only its simple component attributes as columns!
  • Example: If Address is composite with (City, State, Pincode), the resulting table has columns:
  • Rule 3: Multi-Valued Attributes: For each multi-valued attribute A, create a brand-new separate table.
  • The new table contains:

Mapping Weak Entity Sets (Models without External Keys)

  • Rule 4: Weak Entities: A weak entity does not possess a primary key of its own; it relies on an owner entity.
  • Create a relation R containing all simple attributes of the weak entity.
  • Add the Primary Key of the identifying owner entity as a Foreign Key in R.
  • The Primary Key of R is the composite of the Owner’s Primary Key + Partial Discriminator of the weak entity!
  • Example: Weak entity DEPENDENT(Dep_Name, Relationship) owned by EMPLOYEE(Emp_ID):

Mapping Relationships (Binary 1:1, 1:N, M:N)

  • A one-to-many relationship commonly puts the foreign key on the many side.
  • A. One-to-One (1:1) Relationships: Example: CITIZEN(Citizen_ID, Name) and PASSPORT(Passport_No, Issue_Date).
  • Method: Add Citizen_ID as a unique Foreign Key in PASSPORT:
  • B. One-to-Many (1:N) Relationships: Example: One DEPARTMENT employs many EMPLOYEEs.
  • Method: Always put the Primary Key of the “One” side into the “Many” side table!
  • C. Many-to-Many (M:N) Relationships: Example: STUDENT enrolls in COURSE with attribute Grade.
  • Method: A new Junction Table must be created:

View diagram · Relationship Transformation Strategy

Mapping Recursive (Unary) Relationships

  • When an entity relates to itself (e.g., an Employee is managed by another Employee):
  • Add a recursive Foreign Key column within the same table referencing its own primary key!
  • Table: EMPLOYEE(<u>Emp_ID</u>, Name, Salary, Manager_ID)

Mapping EER Specialization and Generalization (4 Options)

  • When transforming Superclasses and Subclasses (e.g., VEHICLE into CAR and TRUCK), designers choose between four options based on…
  • Option A (Multiple Relations for Superclass and Subclasses):
  • Create 1 table for Superclass: VEHICLE(<u>Vehicle_ID</u>, Price, Model).
  • Create tables for each subclass containing its local attributes + Vehicle_ID as FK:
  • Best for: Disjoint or overlapping; preserves normalized data.
  • Option B (Subclass Tables Only):
  • Only create tables for CAR(<u>Vehicle_ID</u>, Price, Model, Num_Doors) and TRUCK(...).
  • Best for: Total specialization with disjoint subclasses (no generic vehicles exist).

Mapping Aggregated Object Sets

  • When an aggregated relationship [EMPLOYEE - WORKS_ON - PROJECT] relates to another entity MACHINERY:
  • Create the relation for the aggregated relationship:
  • Create a new relation connecting the aggregated key to the new entity: