Unit Ii.: Relational Model
Unit Ii.: Relational Model
Unit Ii.: Relational Model
RELATIONAL MODEL
ER and EER diagrams:
Components of ER model, Conventions, Converting ER
diagrams into tables
Relational Model: Basic concepts, Attributes and Domains,
Codd’s rules.
Relational Integrity : Nulls, Entity, Referential integrities,
Enterprise constraints, Views, Schema Diagram.
Case Study
Student / Timetable / Reservation / any data
Management System
E-R Diagrams
relationship borrower
A loan is associated with at most one customer via
borrower
One-To-Many Relationship
In the one-to-many relationship a loan is associated with at
most one customer via borrower, a customer is associated
with several (including 0) loans via borrower
Many-To-Many Relationship
The discriminator (or partial key) of a weak entity set is the set
of attributes that distinguishes among all the entities of a weak
entity set.
Example: EMPLOYEE/SECRETARY,
EMPLOYEE/TECHNICIAN
Another example of super class and sub class:-
Super class
vehicle
truck scooter
Bus car
Sub class
Specialization
Is the process of defining a set of subclasses of a super class.
The set of subclasses is based upon some distinguishing
characteristics of the entities in the super class.
Example: {SECRETARY, ENGINEER, TECHNICIAN} is a
specialization of EMPLOYEE based upon job type.
May have several specializations of the same super class.
Example: Another specialization of EMPLOYEE based in
method of pay is {SALARIED_EMPLOYEE,
HOURLY_EMPLOYEE}.
Super class/subclass relationships and specialization can be
diagrammatically represented in EER diagrams.
student sid
name
is A
Undergrad graduate
student sid
name
is A
Generalization Specialization
Undergrad graduate
Generalization Specialization
Generalization Specialization
Aggregation
The E-R model cannot express relationships among relationships.
When would we need such a thing?
Consider a DB with information about employees who work on a
particular project and use a number of machines doing that work. We get
the E-R diagram shown in Figure
Hours Member
Name Id
Project
Employee Work
Users
Id
Relationship sets work and uses could be combined into a
single set. However, they shouldn't be, as this would obscure
the logical structure of this scheme
For our example, we treat the relationship set work and the
entity sets employee and project as a higher-level entity set
called work.
Hours Member
Name Id
Work Project
Employee Work
Users
Machinery
Id
tuples
(or rows)
Codd's Rules
Codd's twelve rules are a set of
thirteen rules (numbered zero to
twelve) proposed by Edgar F. Codd, a
pioneer of the relational model.
For databases, designed to define what
is required from a database
management system in order for it to
be considered relational, i.e., a
relational database management
system (RDBMS).
0.Foundation Rule
A relational database management system must manage its
stored data using only its relational capabilities.
1. Information Rule
All information in the database should be represented in one
and only one way - as values in a table.
12.Nonsubversion Rule
If a relational system has or supports a low-level (single-
record-at-a-time) language, that low-level language cannot be
used to subvert or bypass the integrity rules or constraints
expressed in the higher-level (multiple-records-at-a-time)
relational language
The Network Model
Relational Model
Network Model
The Hierarchical Model
Similar to the network model
A hierarchical data model is a data model in which the data
is organized into a tree-like structure.
Organization of the records is as a collection of trees, rather
than arbitrary graphs
The structure allows representing information using
parent/child relationships: each parent can have many children
but each child only has one parent (also known as a 1:many
ratio ).
In a database, an entity type is the equivalent of a table
each individual record is represented as a row and
an attribute as a column.
A sample hierarchical database
Schema Diagram
A database schema ,along with primary key and foreign key
dependencies, can be depicted pictorially by schema diagram.
Primary key
Foreign key
Relation
Attribute
Schema Diagram for University Database
Integrity
Integrity constraints are used to ensure accuracy and
consistency of data in a relational database.
Data integrity is handled in a relational database through the
concept of referential integrity.
During the data analysis phase, business rules will identify any
column constraints.
For example, a salary cannot be negative.
an employee number must be in the range 1000 - 2000, etc.
A view also has rows and columns as they are in a real table in
the database.
A View can either have all the rows of a table or specific rows
based on certain condition.
Syntax:
CREATE VIEW view_name AS
SELECT column1, column2.....
FROM table_name
WHERE condition;
Example
CREATE VIEW DetailsView AS
SELECT NAME, ADDRESS
FROM Student_Details
WHERE STU_ID < 4;
SELECT * FROM DetailsView;
Sample table:
Student_Detail
STU_ID NAME ADDRESS
1 Stephan Delhi
2 Kathrin Noida
3 David Ghaziabad
4 Alina Gurugram
Student_Marks
STU_ID NAME MARKS AGE
1 Stephan 97 19
2 Kathrin 86 21
3 David 74 18
4 Alina 90 20
5 John 96 18
Syntax:
CREATE VIEW view_name AS
SELECT column1, column2.....
FROM table_name
WHERE condition;
Creating View from a single table
In this example, we create a View named DetailsView
from the table Student_Detail.
CREATE VIEW DetailsView AS
SELECT NAME, ADDRESS
FROM Student_Details
WHERE STU_ID < 4;
Just like table query, we can query the view to view the data.
SELECT * FROM DetailsView;
NAME ADDRESS
Stephan Delhi
Kathrin Noida
David Ghaziabad
Creating View from multiple tables