Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
3 views43 pages

DBMS Module3

Uploaded by

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

DBMS Module3

Uploaded by

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

Relational Model & Relational Algebra

Module III
Introduction to Relational Model
The relational model in DBMS is an abstract
model used to organize and manage the data
stored in a database.
It stores data in two-dimensional inter-related
tables, also known as relations in which each
row represents an entity and each column
represents the properties of the entity.
What is the Relational Model?
The relational model for database management
is an approach to logically represent and
manage the data stored in a database.

In this model, the data is organized into


a collection of two-dimensional inter-related
tables, also known as relations.
Let's look at a scenario to understand the
relational model:
Consider a case where you wish to store the
name, the CGPA attained, and the roll number
of all the students of a particular class.

This structured data can be easily stored in a


table.
Relational Model Concepts
As discussed earlier, a relational database is
based on the relational model. This database
consists of various components based on the
relational model. These include:

• Relation: Two-dimensional table used to store


a collection of data elements.
• Tuple: Row of the relation, describing a
real-world entity.
• Attribute/Field: Column of the relation,
describing properties that define the relation.
• Attribute Domain: Set of pre-defined atomic
values that an attribute can take i.e., it
describes the legal values that an attribute can
take.
• Degree: It is the total number of attributes
present in the relation.
• Cardinality: It specifies the number of entities
involved in the relation i.e., it is the total
number of rows present in the relation.

• Relational Schema: It is the logical blueprint


of the relation i.e., it describes the design and
the structure of the relation. It contains the
table name, its attributes, and their types:
TABLE_NAME(ATTRIBUTE_1 TYPE_1, ATTRIBUTE_2 TYPE_2, ...)

For our Student relation example, the relational schema will be:

Create table STUDENT(ROLL_NUMBER INTEGER, NAME


VARCHAR(20), CGPA FLOAT);

Roll_Number Name CGPA


Relational Instance: It is the collection of records present
in the relation at a given time.
Relation Key: It is an attribute or a group of attributes
that can be used to uniquely identify an entity in a
table or to determine the relationship between two
tables. Relation keys can be of 6 different types:
▪ Candidate Key
▪ Super Key
▪ Composite Key
▪ Primary Key
▪ Alternate Key
▪ Foreign Key
What are Integrity Constraints in DBMS?

• In Database Management Systems, integrity


constraints are pre-defined set of rules that are
applied on the table fields(columns) or
relations to ensure that the overall validity,
integrity, and consistency of the data present
in the database table is maintained.
Types of relational Constraints
• Domain Constraint
• Domain integrity constraint contains a certain
set of rules or conditions to restrict the kind of
attributes or values a column can hold in the
database table. The data type of a domain can
be string, integer, character, DateTime,
currency, etc.
Example:
Consider a Student's table having Roll No, Name,
Age, Class of students.

Roll No Name Age Class


101 Jignasha 14 6
102 ShriHari 16 8
103 Santosh 8 4
104 Ankur 18 12
105 Ram 6 A
Entity Integrity Constraint
Entity Integrity Constraint is used to ensure that
the primary key cannot be null.
A primary key is used to identify individual
records in a table and if the primary key has a
null value, then we can't identify those
records.
There can be null values anywhere in the table
except the primary key column.
Example:
Consider Employees table having Id, Name, and salary of employees
In the above employee's table, we can see that the ID column is the
primary key and

ID Name Salary
1101 Jignasha 40000
1102 ShriHari 60000
1103 Santosh 80000
1104 Ankur 80000
Ram 36000
Which type of integrity constraint is used to
restrict the type of values a column can hold?
– Domain Constraint
– Entity Constraint
– Referential Integrity Constraint
– Key Constraint
• Referential Integrity Constraint
• Referential Integrity Constraint ensures that
there must always exist a valid relationship
between two relational database tables.
• This valid relationship between the two tables
confirms that a foreign key exists in a table.
• It should always reference a corresponding
value or attribute in the other table or be null.
Example:
Consider an Employee and a Department table where Dept_ID acts as a foreign
key between the two tables
Employees Table
ID Name Salary Dept_ID (FK)
1101 Jignasha 40000 3
1102 ShriHari 60000 2
1103 Santosh 80000 4
1104 Ankur 80000 3
1105 Ram 36000 1

Department Table
Dept_ID(PK) Dept_Name
1 Sales
2 HR
3 Technical
• Key constraint
• Keys are the set of entities that are used to
identify an entity within its entity set uniquely.
There could be multiple keys in a single entity
set, but out of these multiple keys, only one
key will be the primary key.
• A primary key can only contain unique and not
null values in the relational database table.
Example:
Consider a student's table

Roll No Name Age Class


101 Jignasha 14 6
102 ShriHari 16 8
103 Santosh 8 4
104 Ankur 18 12
102 Ram 6 2
• What does the Referential Integrity
Constraint ensure?
– Primary key uniqueness
– Foreign key uniqueness
– Valid relationship between tables
– Data type in column is correct

You might also like