Database Systems and Web (15B11CI312)
Database Systems and Web (15B11CI312)
Database Systems and Web (15B11CI312)
and Web
(15B11CI312)
Database Systems and Web
Lecture 3
Contents to be covered
▪ Entity-Relationship (E-R) Model
▪Entity and Its Attributes
▪Types of Attributes
▪Domain of Attributes
▪Entity types and Entity sets
▪Classification of Constraints
▪Keys
Entity-Relationship (E-R) Model
⚫The ER Model of data is the most widely as conceptual level data model.
⚫ Data model to describe the database system at the requirements collection stage.
Student
Attributes
Each entity is described by a set of attributes/properties.
For example : Attributes of student entity
SName – name of the student.
RNumber – the roll number of the student.
Gender – the gender of the student etc.
Student
Student
Age
Student
DOB
MNumber DOB
PIN
Address
Age
Student
MNumber DOB
2.Single-value constraints
3.Multi-valued constraints
Keys can be determined only from the meaning of the attributes in the entity type and
Determined by the designers
Keys
Super Key – An attribute or a combination of attribute that is used to identify the
records uniquely is known as Super Key.
A table can have many Super Keys.
En_Number Aadhar_ID Name CGPA Address
For example
En_Number : is a Candidate Key
Aadhar_ID : is a Candidate Key
Name, Address : is a Candidate Key
Combination of “Name and Address” can identify the record uniquely, but neither Name nor
Address can be used to identify the records uniquely as it might be possible that we have two
employees with similar name or two employees from the same house.
En_Number,Aadhar_ID: is not a Candidate Key
En_Number,Name: is not a Candidate Key
Keys
Primary Key – A Candidate Key that is used for unique identification of each row in a
table is known as Primary Key. A Primary Key can consist of one or more attributes of a
table.
several candidate keys may exist, one of the candidate keys is selected to be the primary
key. Database designer can use one of the Candidate Key as a Primary Key.
En_Number Aadhar_ID Name CGPA Address
Foreign Key – A foreign key is an attribute or combination of attribute in one base table
that points to the candidate key (generally it is the primary key) of another table. The
purpose of the foreign key is to ensure referential integrity of the data i.e. only values
that are supposed to appear in the database are permitted.
.
Keys
For Example – Consider given two tables i.e. Student Table and Department Table
where RNumber and Dept are Primary Keys.
Now the “Branch” attribute of Student Table (dependent or child table) can be defined
as the Foreign Key as it can reference to the “Dept” attribute of the Departments table
(the referenced or parent table).
A Foreign Key value must match an existing value in the parent table or be NULL.
A Foreign Key must primary key of unique key in parent table.
RNumber Sname CGPA Branch
Dept HOD
1 A 7 CSE
CSE X
2 B 8 ECE
3 C 6 CSE ECE Y
4 D 9 BT BT Z
Primary Keys in E/R Diagrams
Every entity set must have a primary key
Denoted by the underline attribute
Age
Student
MNumber DOB