0% found this document useful (0 votes)
86 views13 pages

The Relational Data Model Final Notes 14-03-2025

Chapter 4 discusses the relational data model, covering its concepts, constraints, and database design using ER-to-relational mapping. It explains the importance of keys and constraints in maintaining data integrity and consistency, as well as the process of converting ER diagrams into logical database designs. The chapter also outlines various types of constraints, including domain, key, entity integrity, and referential integrity constraints, which are essential for ensuring accurate and reliable database operations.

Uploaded by

Putta Swamy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
86 views13 pages

The Relational Data Model Final Notes 14-03-2025

Chapter 4 discusses the relational data model, covering its concepts, constraints, and database design using ER-to-relational mapping. It explains the importance of keys and constraints in maintaining data integrity and consistency, as well as the process of converting ER diagrams into logical database designs. The chapter also outlines various types of constraints, including domain, key, entity integrity, and referential integrity constraints, which are essential for ensuring accurate and reliable database operations.

Uploaded by

Putta Swamy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 13

Chapter – 4

Relational Data Model


Topics Covered:
 Relational Model Concepts
 Relational Model Constraints
 update operations dealing with constraint violations
 Relational Database Design using ER-to-Relational mapping
In this chapter, we'll cover the following topics:
 Why use relational data models?
 What is relational model?
 Fundamental concepts of the relational data model
 Why do we need a key in database design? Which are the different types of keys are used
in database design
 Why do we need constraints in database design? When designing a database, the different
constraints are keep in mind for maintaining ACID properties in database.
 When various update operations performed, how dealing with various constraint
violations.
 Finally know about how Design Relational Database model using ER-diagram
Relational Model Concepts:
 Database design is a two-step process such as conceptual design and Logical design.
 Earlier (in last chapter) we saw how to convert an unorganized text description of
information requirements into a conceptual design, by the use of ER diagrams.
 The advantage of ER diagrams is that you to identify data requirements that are implicitly
known, but not explicitly written down in the original description.
 Here we will see how to convert this ER into a logical design of a relational database.
 The logical design of a database consists in translating the conceptual schema of the data
into a logical schema.
 The logical model is independent of the physical model, i.e. the physical representation of
the data. The logical model that we will use is called relational model (RM).
What is Relational model?
The relational model also called as abstract model is the primary
data model that represents the database as a collection of tables.
The relational model is used widely around the world for data storage and processing
(manage and organise the data) that gets stored in a database.
The relational model consists of two main components:
 The structures that allow to organize the data
 The integrity constraints that allow data to be kept consistent.
History of relational model:
The building blocks of the relational model has been developed on
the concept of mathematical relation and its theoretical concepts are based on set theory and
first-order predicate logic.
It was proposed firstly in 1970 by Edgar F. Codd in his article “A Relational Model for Large
Shared Data Banks”, which appeared in the journal Communications of the ACM.
Various terminologies used in relational model:
The various important terminologies are used in
relational data model are,

Relation: In relational model, table is also called as relation used for stores information. A
relation has combination of rows and columns, where rows represent records and columns
represent the attributes.
Domain: It consists of some atomic values of a particular attribute. It means, a domain tells
which type of value can be stored in a particular column, in the Roll No column it will always
accept the integer value, but it won’t accept the string value.
So, the domain in Relational Model in DBMS is also defined as the set of allowable values
for all the attributes in the tables.
Attribute: Attributes are the properties which define a relation. Each column in a table is
called as attribute. It is the name given to a particular column in a table. Each attribute Ai is
required to have a domain, dom(Ai).
Example: CustomerID, CustomerName, Status.
Tuple: A single row of a table, which contains a single record for that relation is called a
tuple.
Relation key: Each row has one or more attributes, known as relation key, which can
identify the row in the relation (table) uniquely.
Relation instance: A finite (limited) set of tuples in the relational database system represents
relation instance. Relation instances do not have duplicate tuples.
Relation schema: A relation schema describes the relation name (table name), attributes, and
their names. It means, It represents the relation’s name along with its attributes.
Example: EMPLOYEE (ID_NO, NAME, ADDRESS, ROLL_NO, AGE) is the relation
schema for EMPLOYEE. If a schema has more than 1 relation, then it is known as Relational
Schema.
Attribute domain: Every attribute has some pre-defined value scope, known as attribute
domain.
Degree: It refers to the total number of attributes that are there in the relation.
Cardinality: It is just the opposite of the degree, refers to the total number of rows present in
the given table.
NULL Values: The value that is NOT known or the value that is unavailable is known as a
NULL value. This null value is represented by the blank spaces.
E.g., the MOBILE of the EMPLOYEE having ID_NO 4 is NULL.
Characteristics of Relations:
As we know we have several relations in a database. Now, each relation must be uniquely
identified. If it is not so, then it would create a lot of confusion. Here, we will discuss some
characteristics that when followed will automatically make a relation distinct in a database.
1. Each relation in a database must have a distinct or unique name which would separate
it from the other relations in a database.
2. A relation must not have two attributes with the same name. Each attribute must have a
distinct name.
3. Duplicate tuples must not be present in a relation.
4. Each tuple must have exactly one data value for an attribute. For example, below in the
first table, you can see that for Roll_No. 265 we have enrolled two students Jhoson and
Charles, this would not work. We must have only one student for one Roll_No.

Ordering of Tuples in a relation (tuples are unordered top to bottom): A relation is a set
of tuples (rows) and a set has no particular order among its elements. Hence, tuples in a
relation do not have any specified order. However, tuples in a relation can be logically
ordered by the values of various attributes. In that case, information in a relation remains
same, only the order of tuples various. Hence tuple ordering in a relation is irrelevant.

Ordering of Values within a Tuple (Attributes are unordered lift to right): An n-tuple is
an ordered set of attribute values that belongs to the domain D. so, the order in which the
values appear in the tuples is significant. However, if a tuple is defined as a set of
(<attribute>:<value>) pairs, the order in which attribute appears in a tuple is irrelevant. This
is due to the reason that there is no preference for one attribute value over another.
Values and NULLs in the Tuples(Each tuple contains exactly one of value for each
attribute): Relational model is based on the assumption that each tuple in a relation contains
a single value for each of the attribute. Hence, a relation does not allow composite and
multivalued attributes. Moreover, it allows denoting the value of the attributes as NULL, if
the value does not exist for that attribute or the values is unknown.
Interpretation of a relation: A relation can be used to interpret facts about entities as a type
of assertion. A relation can also be used to interpret facts about relationships.

Relational Model Constraints and Relational


Database Schemas:
So far, we have discussed the characteristics of single relations. In a relational database, there
will typically be many relations, and the tuples in those relations are usually related in various
ways. The state of the whole database will correspond to the states of all its relations at a
particular point in time. There are generally many restrictions or constraints on the actual
values in a database state.
In Relational Database model, constraints are guidelines or limitations or restrictions or a set
of rules specified to the data values in the tables to maintain the integrity, correctness
(Accuracy) and consistency (validates the quality) of the data of the database and it ensures
(validates) the various operations like data insertion, updating, and other processes which
have to be performed without affecting the integrity of the data (what values are allowed to
be inserted in the relation, and what kind of modifications and deletions are allowed in the
relation). Thus, constraint is used to guard (protect) us against threats /accidental damage to
the database.
The constraints are specified within the DDL commands like “create” and “alter”
command.
Integrity constraints are rules that help to maintain the accuracy and consistency of data in
a database. They can be used to enforce business rules or to ensure that data is entered
correctly.
Relational Model Constraints:
 Data Accuracy: Data accuracy is guaranteed by constraints, which make sure that only
true data is entered into a database.
 For example: A limitation may stop a user from entering a negative value into a field that
only accepts positive numbers.
 Data Consistency: The consistency of data in a database can be upheld by using
constraints. These constraints are able to ensure that the primary key value in one table is
followed by the foreign key value in another table.
 Data integrity: The accuracy and completeness of the data in a database are ensured by
constraints.
For example: A constraint can stop a user from putting a null value into a field that requires
one.
In this section, we discuss the various restrictions on data that can be specified on a relational
database in the form of constraints. Constraints on databases can generally be divided into
three main categories:
1. Inherent Model-Based Constraints: The constraints that are implicit in a data model are
inherent model-based constraints or implicit constraints.
For example: A relation in a database must not have duplicate tuples, there is no
constraint in the ordering of the tuples and attributes.
2. Constraints that cannot be directly expressed in the schemas of the data model, and hence
must be expressed and enforced by the application programs (The constraints that cannot
be applied while defining the database schema are expressed in application programs).
We call these application-based or semantic constraints or business rules.
For example: The salary of an employee cannot be more than his supervisor (Constraints
that cannot be directly applied in the schemas of the data model. We call these
Application based or Semantic Constraints).
3. Schema-Based Constraints (Explicit Constraints): The constraints that are specified
while defining the schema of a database using DDL are schema-based constraints.
(Constraints that are directly applied in the schemas of the data model, by specifying
them in the DDL).
They are further categorized as,
 Domain constraints
 Key constraints or Uniqueness Constraints
 Entity integrity constraints
 Referential integrity constraints and constraints on Null Value

Domain Constraints:
In a database relation, domain constraints are guidelines (set of rules) that
specify (declared) to be of a particular domain (for example, integer, character, Boolean,
String, etc.). This Constraint also ensures that the value taken by an attribute is an atomic
value. This means that it cannot be divided from its domain.
it means, set of rules which defines what kind of attributes values can be stored in an entity. It
helps us to enter the data into the table according to the particular data type (It means, domain
constraints can be violated if an attribute value is not appearing in the corresponding domain
or it is not of the appropriate data type).
Domain Constraints specify two things:-Data Type and constraints such as NOT NULL,
PRIMARY KEY, FOREIGN KEY, CHECK, etc.
The following are some instances of domain restrictions in a Relational Database Model −
 Data type constraints − These limitations define the kinds of data that can be kept in a
column. A column created as VARCHAR can take string values, but a column specified
as INTEGER can only accept integer values.

 Length Constraints − These limitations define the largest amount of data that may be
put in a column. For instance, a column with the definition VARCHAR(10) may only
take strings that are up to 10 characters long.
 Range constraints − The allowed range of values for a column is specified by range
restrictions. A column designated as DECIMAL (5,2), for example, may only take
decimal values up to 5 digits long, including 2 decimal places.
 Nullability constraints − Constraints on a column's capacity to accept NULL values are
known as nullability constraints. For instance, a column that has the NOT NULL
definition cannot take NULL values.
 Unique constraints − Constraints that require the presence of unique values in a column
or group of columns are known as unique constraints. For instance, duplicate values are
not allowed in a column with the UNIQUE definition.
 Check constraints − Constraints for checking data: These constraints outline a
requirement that must hold for any data placed into the column. For instance, a column
with the definition CHECK (age > 0) can only accept ages that are greater than zero.
 Default constraints − Constraints by default: Default constraints automatically assign a
value to a column in case no value is provided. For example, a column with a DEFAULT
value of 0 will have 0 as its value if no other value is specified.
Key Constraints or Uniqueness Constraints:
Key constraints are also called uniqueness
constraints since it ensures that every tuple in the relation should be unique. A relation can
have multiple keys or candidate keys (minimal super key), out of which we choose one of the
keys as the primary key, we don’t have any restriction on choosing the primary key out of
candidate keys, but it is suggested to go with the candidate key with less number of attributes.
Null values are not allowed in the primary key, hence Not Null constraint is also part of the
key constraint.
In Relational Database Model, there are several key constraint kinds, including:
 Primary Key Constraint − A primary key constraint is an individual identifier for each
record in a database. It guarantees that each database entry contains a single, distinct
value—or a pair of values—that cannot be null—as its method of identification.
 Unique Constraint − In a database, a unique constraint ensures that no two values inside
a column or collection of columns are the same.

Explanation: In the above table, ID is the primary key, and the third and the last tuple
have the same value in ID i.e., 1002, so it is violating the key constraint.
 Foreign Key Constraint − Reference to the primary key in another table is a foreign key
constraint. It ensures that the values of a column or set of columns in one table
correspond to the primary key column(s) in another table.

 Entity Integrity Constraint:
Entity integrity constraint specifies that a primary key of a tuple
can never be NULL. As primary key used to identify individual tuple in a relation.
An entity integrity constraint is enforce rules that guarantee a table's primary key is unique
and not null. The consistency and integrity of the data in a database are maintained by EICs,
which are created to stop the formation of duplicate or incomplete entries.
Example:

Explanation: In the above relation, EID is made the primary key, and the primary key can’t
take NULL values but in the third tuple, the primary key is null, so it is violating Entity
Integrity constraints.
Each item in a table in a relational database is uniquely identified by one or more fields
known as the primary key. EICs make a guarantee that every row's primary key value is
distinct and not null. Take the "Employees" table, for instance, which has the columns
"EmployeeID" and "Name." The table's primary key is the EmployeeID column. An EIC on
this table would make sure that each row's unique EmployeeID value is there and that it is
not null.
If you try to insert an entry with a duplicate or null EmployeeID, the database management
system will reject the insertion and produce an error. This guarantees that the information in
the table is correct and consistent.
EICs are a crucial component of database architecture and assist guarantee the accuracy and
dependability of the data contained in a database.
 Referential Integrity Constraint:
The Referential integrity constraint is specified between two
relations or tables and used to maintain the consistency among the tuples in two relations.
This constraint is enforced through a foreign key, when an attribute in the foreign key of
relation R1 has the same domain(s) as the primary key of relation R2, then the foreign key of
R1 is said to reference or refer to the primary key of relation R2.
The values of the foreign key in a tuple of relation R1 can either take the values of the
primary key for some tuple in relation R2, or can take NULL values, but can’t be empty.
The referential integrity constraint holds if the foreign key of relation R1 that refers to the
relation R2 satisfies following two conditions:
1. The set of attributes that form foreign key of relation R1 should have the same
domain as the primary key of the referenced relation R2.
2. In the current state, the set of values of the foreign key in tuple t1 of relation R1
must match a primary key value in referenced relation R2 or it could be NULL.

Explanation: In the above tables, the DNO of Table 1 is the foreign key, and DNO in Table
2 is the primary key. DNO = 22 in the foreign key of Table 1 is not allowed because DNO =
22 is not defined in the primary key of table 2. Therefore, Referential integrity constraints are
violated here.
Operations in Relational Model: Four basic update operations performed on relational
database model are
Insert, update, delete and select.
 Insert is used to insert data into the relation
 Delete is used to delete tuples from the table.
 Modify allows you to change the values of some attributes in existing tuples.
 Select allows you to choose a specific range of data.
Whenever one of these operations are applied, integrity constraints specified on the relational
database schema must never be violated.
Insert Operation: The insert operation gives values of the attribute for a new tuple which
should be inserted into a relation.

Update Operation
You can see that in the below-given relation table CustomerName= ‘Apple’ is updated from
Inactive to Active.

Delete Operation
To specify deletion, a condition on the attributes of the relation selects the tuple to be deleted.

In the above-given example, CustomerName= “Apple” is deleted from the table.


The Delete operation could violate referential integrity if the tuple which is deleted is
referenced by foreign keys from other tuples in the same database.
Select Operation

In the above-given example, CustomerName=”Amazon” is selected


Properties of relational tables
1. Each row is unique
2. Values are atomic
3. Column values are of the same kind
4. The sequence of columns is insignificant
5. The sequence of rows is insignificant
6. Each column has a unique name

You might also like