The Relational Data Model Final Notes 14-03-2025
The Relational Data Model Final Notes 14-03-2025
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.
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.