The Relational Data Model: Dr. Enosha Hettiarachchi
The Relational Data Model: Dr. Enosha Hettiarachchi
Model
Dr. Enosha Hettiarachchi
Relational Model
Row
Row
Relational Model
Row
Row
Employee
Name Designation Department
Row De Silva Manager Personnel
Row Perera Secretary Personnel
Row Dias Manager Sales
Relational Model Terminology
Relation Schema:
– A relation schema defines the structure of a specific table (or
relation) in a database.
– It outlines what information the table holds by specifying the
table's name and listing its attributes (columns).
– Think of the relation schema as the blueprint for a table,
describing the type of data stored and how it is organized, but not
the actual data itself.
For example, a relation schema for a "Student" table
could be defined as:
– Student (StudentID, Name, Age, Major)
– This schema indicates that the "Student" table will have columns
for StudentID, Name, Age, and Major.
Relation schema and Attributes
Attributes:
– Attributes are the individual columns listed in a relation schema,
each representing a specific type of information that the table
stores.
– Each attribute has a domain, which defines the set of possible
values it can hold (like integers, text, or dates).
– In the example of the "Student" table:
StudentID could be an integer representing a unique identifier for
each student.
Name might be a string storing each student’s name.
Age could be an integer for the student’s age.
Major could be a string that specifies the student’s field of study.
In this example:
– The schema is Employee(EmployeeID, Name, Position, Salary).
– The instance is the actual data shown in the table at this point in time
(three rows of data).
For example:
– If a table Students has 50 records (rows), the cardinality of the
Students table is 50.
– If a table Orders contains 2000 rows, the cardinality of the Orders
table is 2000.
Concepts of keys
Candidate Key
Properties:
– Unique: Each candidate key uniquely identifies a row in the table.
– Minimal: Each candidate key contains only the necessary
attributes to ensure uniqueness.
Primary Key
Properties:
– Uniqueness: No two rows can have the same value for the
primary key.
– Non-null: A primary key must have a value for every record
(cannot be NULL).
Alternate Key
Properties:
– Uniqueness: Like the primary key, alternate keys ensure that
values are unique.
– Can allow NULL values: Unlike the primary key, alternate keys
may allow NULL values (but typically only one NULL value is
allowed).
Composite Key
Properties:
– Composed of multiple columns.
– Ensures uniqueness when combined but not individually.
Surrogate Key
Properties:
– Typically numeric and auto-incremented.
– Does not have any inherent meaning or relation to the real-world
data.
Foreign Key
Properties:
– Ensures referential integrity: Values in the foreign key must
match values in the referenced primary or unique key.
– May allow NULL values, depending on the relationship.
Summary of Key Types:
Entity Integrity
Primary Key: An attribute (or combination of
attributes) that uniquely identifies each row in a
relation.
Employee(Emp_No, Emp_Name, Department)
Composite Key: A primary key that consists of more than
one attribute.
Salary(Emp_No, Eff_Date, Amount)
Referential Integrity
The referential integrity constraint is specified between two
relations and is used to maintain the consistency among tuples
of the two relations.
Referential integrity/Foreign keys
EMPLOEE
DEPT
Relationship
Foreign Key: An attribute in a relation of a
database that serves as the primary key of
another relation in the same database.
Employee(Emp_No, Emp_Name, Dept_No)
Department(Dept_No, Dept_Name, M_No)
50
Relational Objects
COMPANY Database
Update Operations on Relations
Domain constraint
– if one of the attribute values provided for the new tuple is not of
the specified attribute domain
Key constraint
– if the value of a key attribute in the new tuple already exists in
another tuple in the relation
Entity integrity
– if the primary key value is null in the new tuple
Referential integrity
– if a foreign key value in the new tuple references a primary key
value that does not exist in the referenced relation
Example
Insert <‘John’, ‘M’, ‘Doe’, NULL, ‘1977-01-01’, ‘123 Main, TX’, ‘M’,
45000, NULL, 4> into EMPLOYEE will violate entity constraint
Insert <‘Mary’, ‘M’, ‘Doe’, 123456789, ‘1977-01-01’, ‘123 Main, TX’,
‘M’, 45000, NULL, 4> into EMPLOYEE will violate key constraint
Teaching Professor
x
x
Request to delete a row
in Professor