Unit 3
Unit 3
2. Not null
This constraint ensures that each column of all the
rows in the table has some value (data).
Any column value cannot be NULL (empty).
3. Unique Key
Ensures that the data in each row for a single or
group of columns is unique (distinct).
A column can have NULL values, but cannot be
duplicated.
Integrity E.g. Roll Number of a student is Unique.
Constraint
4. Primary Key
Ensures that a column or a group of columns
identify uniquely each row in the table.
A column cannot have NULL values and cannot be
duplicated.
E.g. Roll Number of a student is Unique.
5. Foreign Key
Also known as Referential Integrity Constraint
Allows a table to refer a column of another table
with Primary Key
For e.g. Primary Key
Integrity Student (sroll, sname, std)
Constraint Result (sroll, m1, m2, m3, result)
Department
Database
Models Manager Worker
(Hierarchical
Model) The data is organised into tree-like structure with
one data component connected to many other data
components.
For example, one department can have many
managers and many workers.
In this, the data is organized into a tree-like structure,
where each record can have multiple parents or roots.
A
Database
Models B C
(Network
Model)
D E F
2 Meet 22
Tuples
Object oriented data model is based upon real world
situations.
E-R Diagram
(Entity) Employee Example
Employee
Symbol Example
Attributes)
Employee ID
Phone Number
Derived Attributes
It’s value is derived or
calculated from other
attributes.
E-R Diagram For e.g. Age of a person can be
easily known from his/her
(Types of birthdate
Attributes) Symbol:
Age
Middle
Name
First Name Last
Name
Single
Simple
Value
ID Name Composite Apartment
Example) Multiple
Value Phone
Birth Date Area
No
1. Create E-R Diagram for college database. Use all types of Attributes
2. Create E-R Diagram for hotel database. Use all types of Attributes
Relationship is link between several entities.
It must be placed between two entities and a line
linking it to an entity.
A relationship is represented by a diamond
containing relationship details.
E-R Diagram A Relationship between 2 Entities is called Binary
(Relationship Relationship and A Relationship between 3 Entities
is called Ternary Relationship.
Set)
Example
Relationship
Student
Detail
Symbol
Book Issue
It defined number of entities of one entity set
connected to number of entities of another entity
set using a relationship set.
Mapping
Cardinality
(One to One)
Set A Set B
For e.g. One Customer is
connected with only one
Loan and One Loan is
customer borrow loan
connected to only One
Customer using Borrow
Relationship Set.
An entity in entity set A is associated with any number
(more than 1) of entities in entity set B. An entity in
entity set B is associated with at only one entity in entity
set A.
Mapping
Cardinality
(One to Many)
Set A Set B
One Customer is
For e.g. connected with more
than one Loan; but, One
customer borrow loan
Loan is connected to only
One Customer using
Borrow Relationship Set.
An entity in entity set A is associated with only one
entity in entity set B. An entity in entity set B is
associated with more than one entities in entity set A.
Mapping
Cardinality
(Many to One)
Set A Set B
One Loan is connected to
For e.g. more than one
Customers; but, One
customer borrow loan Customer is connected
with only one Loan using
Borrow Relationship Set.
More than one entities in entity set A is associated with
more than one entities in entity set B. More than one
entities in entity set B is associated with more than one
entities in entity set A.
Mapping
Cardinality
(Many to
Many)
Set A Set B One Loan is connected to
For e.g. more than one Customers
and One Customer is
customer borrow loan connected with more
than one Loan using
Borrow Relationship Set.
It specifies the participation of an entity set in a
relationship set.
There are two types participation constraints:
Total participation:
every entity in the entity set participates in at least
Participation one relationship in the relationship set. It is
Constraints denoted by Double Line
Partial participation
some entities in the entity set may not participate in
any relationship in the relationship set. It is denoted
by Single Line
Partial Participation Total Participation
Participation C1 L1
Constraints C2 L2
(Example) C3
Customers Loan
An entity set that does not have a primary key is
called weak entity set.
It is denoted by double rectangle symbol.
When a weak entity set is connected with strong
entity set by some relation, then the relation is
known as Weak Relationship Set.
Weak Entity It is denoted by Double Diamond.
Set A Discriminator in Weak Entity Set distinguishes all
other entities.
It is denoted by Dashed Line
To make Relationship stronger, the Primary Key is
created by combining Discriminator of Weak Entity
Set and Primary Key of Strong Entity Set.
Discriminator
Payment-date
amount Payment-
loan-no payment-no
amount
Weak Entity
Strong Weak Entity Weak Entity
Set (Example) Entity Set Relationship Set
Customer
Company
Borrow Borrow
Loan Loan
E R E E R E
E R E E R E
Many to One Many to Many
E-R Diagram
(Example)
Draw E-R Diagram for the following:
1) Hospital Management
2) School Management
3) Library Management
E-R Diagram 4) Hotel Management
(Home Work) 5) Bus/Airline/Train Reservation