0% found this document useful (0 votes)
3 views

Relational Data Model

The document provides an overview of the Relational Data Model, detailing its structure, terminology, and key concepts such as keys, foreign keys, and integrity constraints. It explains the organization of data in tables, the significance of domains and atomicity, and the role of query languages in database management. Additionally, it emphasizes the importance of maintaining data integrity through various constraints in relational databases.

Uploaded by

Prem Pandu
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Relational Data Model

The document provides an overview of the Relational Data Model, detailing its structure, terminology, and key concepts such as keys, foreign keys, and integrity constraints. It explains the organization of data in tables, the significance of domains and atomicity, and the role of query languages in database management. Additionally, it emphasizes the importance of maintaining data integrity through various constraints in relational databases.

Uploaded by

Prem Pandu
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

UNIT-I

Chapter -II – Relational Data Model

Syllabus:
Introduction to the Relational Model: Structure of Relational Databases, Keys, Database
Schema, Relational Query Languages, Relational Operations.

1. Relational Model
The relational model is an abstract model used to organize and manage data in a database. It
stores data in two-dimensional interrelated tables, also known as relations. This model is the
primary data model used for commercial data processing applications.
2. Structure of Relational Databases
A relational database consists of a collection of tables, each assigned a unique name.
For example, consider the instructor table below, which stores information about instructors.
The table has four columns: ID, Name, Dept_Name, and Salary. Each row in the table
represents an instructor's record.
Table: Instructor

ID Name Dept_Name Salary

101 Alice CS 70000

102 Bob Math 65000

103 Charlie Physics 72000

Terminology in the Relational Model


• A relation refers to a table in the relational model.
• A tuple refers to a row in the table.
• An attribute refers to a column in the table.
• A relation instance is a specific set of rows in a relation at a given time.
For example, in the Instructor relation above:
• The relation has four attributes: ID, Name, Dept_Name, and Salary.
• The current instance of Instructor has three tuples, corresponding to three instructors.
• The order in which tuples appear in a relation does not matter, as a relation is a set of
tuples.

CS222 - DATABASE MANAGEMENT SYSTEMS 1


3. Domains and Atomicity
For each attribute in a relation, there is a set of permitted values known as the domain of that
attribute.
Examples of Domains:
• Salary: A set of all possible salary values.
• Name: A set of all possible instructor names.
• Dept_Name: A set containing {CS, Math, Physics, ...}.
A domain is atomic if its values are considered indivisible units.
For example:
• If an Instructor relation had an attribute Phone_Number, which stores a set of phone
numbers for each instructor, the domain would not be atomic because each value
contains multiple numbers.
4. Null Values
The null value is a special value that indicates that the data is unknown or does not exist. For
example, if an instructor's salary is missing, the corresponding tuple may have a NULL value
in the Salary column.
5. Database Schema
The database schema represents the logical design of the database, defining the structure of the
data.
• A database instance is a snapshot of the data in the database at a specific moment in
time.
• The concept of a relation corresponds to a variable in programming languages, whereas
a relation schema corresponds to a type definition.
• A relation schema consists of a list of attributes and their corresponding domains.
• A relation instance represents a current state of a relation, and it may change over time
as updates occur.
Example: Department Relation Schema

department (dept_name, building, budget)

• The attribute dept_name appears in both the instructor schema and the department
schema. This duplication allows for linking data between different relations.

CS222 - DATABASE MANAGEMENT SYSTEMS 2


• To find instructors working in the Watson building, we first check the department
relation for departments in Watson, then retrieve instructors from the instructor relation
who belong to those departments.

Keys

Keys in the Relational Model


Keys play an essential role in relational databases. They help uniquely identify tuples
(records) in a table and establish relationships between different tables.
Super Key
A super key is a set of one or more attributes that can uniquely identify tuples in a relation.
Example:
• {ID} is a super key for the Instructor relation.
• {ID, Name} is also a super key, but ID alone is sufficient to uniquely identify an
instructor.
Candidate Key
A candidate key is a minimal super key, meaning that it uniquely identifies a tuple, but no
proper subset of it can be a super key.
Example:
• {first_name, last_name} is a candidate key for the Employee relation because it
uniquely identifies each employee and neither first_name nor last_name alone can
identify an employee uniquely.
Primary Key
A primary key is a candidate key that is chosen by the database designer to uniquely identify
tuples in a relation.
Example:
• {ID} is chosen as the primary key for the Instructor relation.
Alternate / Secondary Keys
A table can have multiple candidate keys, but only one is selected as the primary key. The
remaining candidate keys are called alternate keys (or secondary keys).
Example:
• If both {ID} and {Email} uniquely identify a student in a Student relation, and {ID}
is chosen as the primary key, then {Email} becomes an alternate key.

CS222 - DATABASE MANAGEMENT SYSTEMS 3


Foreign Key
A foreign key is an attribute in one relation that refers to the primary key of another relation,
establishing a link between the two tables.
Example:
• The Instructor relation has an attribute dept_name, which is a foreign key referencing
the Department relation, where dept_name is the primary key.
Referential Integrity Constraint
A referential integrity constraint ensures that a foreign key value must exist in the referenced
table.
Example:
• If an instructor is assigned to a department, that department must exist in the
Department relation.
Types of Referential Integrity Constraints
1. Insert Constraint: A new tuple cannot be inserted into the referencing relation if the
referenced relation does not contain the corresponding value.
o Example: If a new instructor is added with dept_name = 'Biology', but no
department named Biology exists in the Department table, the insertion is
rejected.
2. Delete Constraint: A tuple cannot be deleted from the referenced relation if it is being
used in the referencing relation.
o Example: If a department is removed from the Department table while
instructors are still assigned to it, the deletion is restricted.
Domain Integrity Constraint
• Ensures that values stored in an attribute belong to a specified domain.
• Prevents invalid data entry.
Example: If the Salary column is defined to accept only positive numbers, the database will
reject negative values.
Entity Integrity Constraint
• Ensures that each row has a unique identifier and no primary key value is NULL.
• A table’s primary key must always have a value.
Example: Each student must have a unique ID and ID cannot have NULL value

These key constraints help maintain data integrity and establish meaningful relationships
between tables in a relational database.

CS222 - DATABASE MANAGEMENT SYSTEMS 4


Database Schema Diagrams

➢ A database schema, along with primary key and foreign key dependencies, can be
depicted by schema diagrams.
➢ Below Figure shows the schema diagram for our university organization. Each
relation appears as a box, with the relation’s name at the top in blue, and the attributes
listed inside the box.
➢ Primary key attributes are shown underlined. Foreign key dependencies appear as
arrows from the foreign key attributes of the referencing relation to the primary key
of the referenced relation.

Figure 2: Schema diagram for the university database.


Query Languages
A query language is a language used to request information from a database. These languages
operate at a higher level than standard programming languages and enable users to retrieve,
manipulate, and manage data efficiently.
Types of Query Languages
Query languages can be categorized into two types:
• Procedural Query Languages:
o The user specifies how to obtain the desired result by providing a sequence of
operations. Example: Relational Algebra
• Nonprocedural Query Languages:
o The user specifies what information is needed without detailing the retrieval
process. Examples: Tuple Relational Calculus (TRC) and Domain Relational
Calculus (DRC)

CS222 - DATABASE MANAGEMENT SYSTEMS 5

You might also like