Database Systems and Web (15B11CI312)

Download as pdf or txt
Download as pdf or txt
You are on page 1of 24

Database Systems

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.

⚫Defines high level description.

⚫Very easy to understand.


Entity-Relationship (E-R) Model
Main concept of ER model:

Diagrammatic notation of Entities, attributes of entities and relationships


between entities.

Entity-Relationship (E-R) Diagram

A detailed, logical representation of the entities, associations and data


elements for an organization or business. Diagrammatic notation
associated with the ER model, known as ER diagrams.
Entity
ƒEntity : An entity may be an object with a physical or conceptual existence.
For example :
particular person, car, house, company etc.
In the context of University database, an individual student, faculty member, a class
room and a course are entities.
An Entity is denoted by rectangle with entity name

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

Attribute are denoted by ellipse


SName RNumber Gender
Types of Attributes
Simple Attributes
◦ ƒAn attribute having atomic or indivisible values.
For example: RNumber
Gender

Student

SName RNumber Gender


Types of Attributes
Composite Attributes
ƒAttributes having several components in the value.
For Example: Student Name
Student
Student Address
College Address
SName RNumber Gender

First Middle Last


Name Name Name

Composite Attribute is represented as a tree like structure


Types of Attributes
Derived Attributes
The value of an attribute is dependents on some other attribute.
example: Age depends on DateOf Birth, so age can be a derived attribute.

Age
Student

DOB

SName RNumber Gender

Derived attributes are represented by dashed ellipse


Types of Attributes
Multi-valued
ƒ Attribute having a set of values rather than a single value.

For Example : Courses Enrolled attribute for student


Mobile Number attribute for student
Previous Degree attribute for student.
Age
Student

MNumber DOB

SName RNumber Gender


Domains of Attributes
⚫Each attribute takes values from a set called its domain

For Example: StudentAge – {17,18, …, 55}

HomeAddress – character strings of length 35

⚫Domain of composite attributes –

cross product of domains of component attributes

⚫Domain of multi-valued attributes –

set of subsets of values from the basic domain


E-R Diagram With Composite,
Multivalued, and Derived Attributes
block City State

PIN
Address

Age
Student

MNumber DOB

SName RNumber Gender


Classification of Constraints
1.Keys

2.Single-value constraints

3.Multi-valued constraints

4.Mapping Cardinalities and Participation Constraints


Entity Type and Entity Sets
An entity type defines a collection (or set) of entities that have the same
attributes. Each entity type in the database is described by its name and
attributes.

The collection of all entities of a particular entity type in the database at


any point in time is called an entity set.
Reading Suggestion and image source : Elmasri and Navathe , ” FUNDAMENTALS OF DATABASE SYSTEMS”
Key Attributes
Key – an attribute or a collection of attributes whose value(s) uniquely identify an
entity in the entity set.
For Example:
• Enrollment Number- Key for Student entity set
• EmpID - Key for Faculty entity set
Key Attributes
A key for an entity set may have more than one attribute.
For Example :
HostelName, RoomNo - Key for Student entity set
(assuming that each student gets to stay in a single room)

An entity set may have more than one key.


For Example :
Enrollment number, aadhar card number, voter id number

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

Example of Super Key for given schema


1 En_Number 2 Aadhar_ID
3 En_Number, Name 4 Aadhar_ID, Name
5 En_Number, Address 6 Name, Address
7 Name, Address, CGPA …………
So on as any combination which can identify the records uniquely will be a Super Key.
Keys
Candidate Key – It can be defined as minimal Super Key or irreducible Super Key
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

For Example Note:. In this example we have “En_Number”, “Aadhar_ID”


and “Name, Address” as Candidate Key. A good database
1. En_Number designer will consider “En_Number” or “Aadhar_ID” Key as a
Primary Key as the other key is the combination of more than
2. Aadhar_ID one attribute.
3.Name,Address
Keys
Alternate Key – Alternate Key can be any of the Candidate Keys except for the Primary
Key.
For example :
◦ Suppose database designer has consider “En_Number” as primary key , Then remaining
Candidate Keys “Aadhar_ID” and “Name, Address” will treat as Alternate Key
En_Number Aadhar_ID Name CGPA Address
Composite Key – There may be no single attribute which can be treat as key, in this
case we use multiple attributes to create a Primary Key then that Primary Key is called
Composite Key (also called a Compound Key or Concatenated Key).
For Example :
◦ Assume “En_Number” and “Aadhar_ID” are not the part of given schema . In this case we
will use “Name, Address” as a Primary Key and then it will be our Composite Key.
Keys

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

SName RNumber Gender

You might also like