Relational Model (Unit-2)
Relational Model (Unit-2)
The Relational Data Model (RDM) is a way of organizing data into tables, called relations, where data is stored in
rows and columns. This model was introduced by E.F. Codd in 1970 and is widely used in Relational Database
Management Systems (RDBMS) like MySQL, PostgreSQL, and SQL Server.
Key Components of the Relational Data Model 4. Domain:
1. Relation (Table): The domain defines the possible values for an attribute.
A relation is a table with unique rows and columns. Example: The "Age" column might have a domain of
Each table represents an entity (e.g., Employees, integers between 1 and 120.
Products). 5. Primary Key (PK):
2. Tuple (Row): A unique identifier for each record in a table.
A tuple is a single record in a table. Example: "Student_ID" in a Student table.
Each row contains values for different attributes. 6. Foreign Key (FK):
3. Attribute (Column): A column that links to the primary key of another table.
Attributes are the columns in a table, representing Used to establish relationships between tables.
data fields. 7. Constraints:
Each attribute has a specific data type (e.g., integer, Rules to maintain data integrity (e.g., NOT NULL,
text, date). UNIQUE, CHECK)
E. F. Codd’s 12 Rules for the Relational Model
E. F. Codd, the father of relational databases, defined 12 rules (actually 13, including Rule 0) to determine
whether a database management system (DBMS) is truly relational. These rules ensure data integrity,
consistency, and structure in relational databases.
Rule 0: The Foundation Rule Rule 7: High-Level Insert, Update, and Delete
Rule 1: Information Rule Rule 8: Physical Data Independence
Rule 2: Guaranteed Access Rule Rule 9: Logical Data Independence
Rule 3: Systematic Treatment of NULL Values Rule 10: Integrity Independence
Rule 4: Dynamic Online Catalog (Data Dictionary) Rule 11: Distribution Independence
Rule 5: Comprehensive Data Sublanguage Rule Rule 12: Nonsubversion Rule
Rule 6: View Updating Rule
Relational Algebra
Relational Algebra is a fundamental concept in databases used to query and manipulate relational data.
Relational operators in relational algebra can be classified into Traditional and Special operators.
Types of Relational Operators
Relational Operators can be broadly classified into two types
Traditional Relational Operators
3. Set Difference (-) – Returns tuples in one
Special Relational Operators relation but not in another.
Traditional Relational Operators: Example: A - B → Includes tuples in A but not in
B.
1. Union (∪) – Combines tuples from two relations
(tables), removing duplicates. 4. Cartesian Product (×) – Combines every tuple
of one relation with every tuple of another.
Example: A ∪ B → Includes all unique tuples from A and
B. Example: A × B → Forms all possible pairs of
tuples from A and B.
2. Intersection (∩) – Returns common tuples between
two relations. 5. Rename (ρ) – Renames a relation or its
attributes.
Example: A ∩ B → Includes only tuples present in both A
and B. Example: ρ(NewName, Employee) → Renames
the Employee relation to NewName.
Special Relational Operators:
1. Selection (σ) – Filters rows (tuples) based on a condition.
Example: σ Age > 30 (Employee) → Selects employees older than 30.
2. Projection (π) – Extracts specific columns (attributes).
Example: π Name, Age (Employee) → Selects only the Name and Age columns.
3. Join (⨝) – Combines related tuples from two relations based on a condition.
Types of Joins:
Theta Join (⨝ θ) – Uses a general condition (e.g., A ⨝ A.id = B.id B).
Equi-Join – A special case of Theta Join using only =.
Natural Join (⋈) – Joins on attributes with the same name.
4. Division (÷) – Used for queries like "Find those who have all required attributes."
Example: A ÷ B → Finds tuples in A that relate to all tuples in B.
Relational Calculus
Relational Calculus is a non-procedural query language in relational databases, meaning it focuses on what
to retrieve rather than how to retrieve it (unlike Relational Algebra, which specifies a step-by-step process).
Queries in relational calculus are expressed as logical formulas, describing the properties of data to be
retrieved.
Types of Relational Calculus
2. Domain Relational Calculus (DRC)
1. Tuple Relational Calculus (TRC) Uses domain variables that represent column values
Uses tuple variables to represent rows in a relation. (attributes) rather than entire tuples.
Queries are expressed using predicate logic. General format:
General format: \{ (x_1, x_2, ..., x_n) \ | \ P(x_1, x_2, ..., x_n) \}
\{ t \ | \ P(t) \} Example: