Database Management System (DBMS)
Course Code: CSI 223
Semester: Summer '06
Lecturer:
Kamruddin Md. Nur
Dept. of Computer Science
Stamford University Bangladesh
L-6: Office:
Siddeswari
Entity Relationship Modelling Block A
Room # 216
Ph: (02) 8355512-14 x-214
Cell: 0191 309 708
Email:
[email protected] Blogs: http://moonbd.blogspot.com
Lecture Content
● Entity Relationship (ER) Model
● Entities, Attributes, Relationships
● Degree of Relationships
● Single-value, Multi-value attributes
● Strong, Week entities
● Keys
● Structural Constraints
Reading: Chapter - 11 Text Book
© Kamruddin Nur 2
Why Modelling ?
The fact that database designers, programmers, and end-users
view the data and its use differently
To solve this problem we need to have a model for communication
which is -
- non-technical
- free of ambiguities
- Entity-Relationship (ER) model is one of them
© Kamruddin Nur 3
ER Model
Top-down approach following the steps -
➔ Identify important data called entities
➔ Identify relationships between data
➔ Identify attributes of entities
➔ Identify constraints on entities, relationships and attributes
© Kamruddin Nur 4
Entity Types
● Entity Type: A group of objects with the same properties, which are
identified by the enterprises as having an independent existence.
● Entity Occurrence: A uniquely identifiable object of a entity type.
Rectangle labeled with the name of
Entity name the entity.
In UML representation, the first letter
of the entity name is a capital letter.
© Kamruddin Nur 5
Relationship Types
● Relationship Type: A set of meaningful associations among entity
types.
● Relationship Occurrence: A uniquely identifiable association, which
includes one occurrence from each participating entity type.
First capital letter.
Has
Branch Staff Only labeled in one direction.
Arrow simbol
© Kamruddin Nur 6
Degree of Relationship Types
● Degree of Relationship type: the number of participating entity
types in a relationship.
● A relationship of degree two is called binary, a relationship of
degree three is called ternary...
Solicitor
Staff Registers Branch
Buyer Arranges Financial
Institution
Client
Bid
“Staff registers a client at a branch”
“A solicitor arranges a bid on behalf of a
buyer supported by a financial institution”
© Kamruddin Nur 7
Recursive Relationship
● Recursive Relationship: A relationship type where the same entity
type participates more than once in different roles.
Manages
Staff Branch
Has
© Kamruddin Nur 8
Attributes
● Attribute: A properity of an entity or a relationship type. For
example: staffNo, name, position... To describe the entity Staff.
● Attribute Domain: The set of allowable values for one or more
attributes.
● Attributes can be classified as being: simple or composite; single-
valued or multi-valued; or derived.
© Kamruddin Nur 9
Simple and Composite Attributes
● Simple Attribute: An attribute composed of a single component with
an independent existence. E.g position and salary of the Staff entity.
● Composite Attribute: An attribute composed of multiple
components, each with an independent existence.
● E.g adress attribute of the branch entity that can be subdivided into
street, city and postcode attributes.
© Kamruddin Nur 10
Single-Valued and Multi-Valued Attributes
● Single-Valued Attribute: An attribute that holds a single valuefor
each occurrence of an entity type. E.g branchNo.
● Multi-Valued Attributes: An attribute that holds multiple values for
each occurrence of an entity type. E.g telephoneNo.
© Kamruddin Nur 11
Derived Attributes
● Derived Attributes: An attribute that represents a value that is
derivable from the value of a related attribute or set of attributes, not
necessarily in the same entity type.
● E.g attribute duration which value is derived from the rentStart and
rentFinish attributes.
© Kamruddin Nur 12
Keys
● Candidate Key (never NULL): The minimal set of attributes that
uniquely identifies each occurrence of an entity type.
E.g: branchNo in entity Branch.
● Primary Key: The candidate key that is selected to uniquely identify
each ocurrence of an entity type.
E.g:National Insurance Number.
● Composite Key: A candidate key that consist of two or more
attributes.
© Kamruddin Nur 13
Diagramatic Representation of attributes
Primary
Key
Staff Branch
branchNo
satffNo {PK} Manages
{PK}
Area to list name
Address
attributes position Composite
street
salary/totalStaf Has
city attribute
f
postcode
telNo[1..3]
Derived
attribute Multi-valued
attribute
© Kamruddin Nur 14
Strong and Weak Entity Types
● Strong Entity Type: An entity type that is not existence-dependent
on some other entity type.
● Weak Entity Type: An entity type that is existence-dependent on
some other type.
STRONG ENTITY WEAK ENTITY
Client Preference
States
clientNo {PK} prefType
name maxRent
fName
lName
telNo
© Kamruddin Nur 15
Attributes on Relationships
● Attributes can also be assigned to relationships.
Newspaper Advertises ProperityForRent
newspaperName properityNo
•Dashed line!!
dateAdvert
cost
© Kamruddin Nur 16
Structural Constraints
● Multiplicity: The number (or range) of possible occurrences of
an entity type that may relate to a single occurrence of an
associated entity type through a particular relationship.
· One-to-one (1:1)
· One-to-many (1:*)
· Many-to-many (*:*)
© Kamruddin Nur 17
One-to-One (1:1)
Staff Branch
Manages
staffNo 1..1 0..1 branchNo
“Each branch is managed by “A member of staff can manage
One member of the staff” zero or one branch”
© Kamruddin Nur 18
One-to-Many (1:*)
Staff ProperityForRent
Oversees
staffNo properityNo
0..1 0..*
“Each properity for rent is “Each member of staff
overseen by zero or one oversees zero or more
member of staff” properitys for rent”
© Kamruddin Nur 19
Many-to-Many (*:*)
Newspaper ProperityForRent
Advertises
newspaperNa 0..* 1..* properityNo
me
“Each properity for rent is “Each newspaper advertises one
advertised in zero or more or more properties for rent”
newspapers”
© Kamruddin Nur 20
Multiplicity for Complex Relationships
●
Multiplicity (complex relationships): The number (or range) of
possible occurrences of any entity type in any n-ary relationship when
the other (n-1) values are fixed.
Staff Registers Branch
1..1 1..1
0..*
Client
© Kamruddin Nur 21
ERD: An Example
✔ I need to maintain the information I use to contact people
✔ Maintain contact information
✔ Maintain some social information
© Kamruddin Nur 22
An Example: Address Book cont.
“I use the address book to look up addresses and phone
numbers of friends and businesses. I also contact some
people by email and look at businesses’ Web sites. Some
friends are on my holiday list, and I want to send them
cards that are addressed with spouse and children’s
names. I send some friends birthday cards.”
© Kamruddin Nur 23
An Example : Address Book cont.
“I use the address book to look up addresses and phone
numbers of friends and businesses. I also contact some
people by email and look at businesses’ Web sites. Some
friends are on my holiday list, and I want to send them
cards that are addressed with spouse and children’s
names. I send some friends birthday cards.”
© Kamruddin Nur 24
ERD: An Example cont.
Noun = Entity
Verb = Relationship
Piece of Information = Attribute of an Entity
© Kamruddin Nur 25
An Example: Address Book cont.
Preliminary Entities:
Friends
Business
People
Holiday list
© Kamruddin Nur 26
Address Book: Preliminary Attributes
Friends ●
friendName
Business
●
friendAddress
●
friendPhone
People
●
friendFax
Holiday list
●
friendEmail
© Kamruddin Nur 27
Address Book: Preliminary Attributes
Friends ●
friendName • businessPhone
Business
●
friendAddress • businessFax
●
friendPhone • businessEmail
People
●
friendFax
Holiday list • businessURL
●
friendEmail
●
businessName
●
businessContact
●
businessContactPos
© Kamruddin Nur 28
Address Book: Preliminary Attributes
Friends ●
friendName • businessPhone
Business
●
friendAddress • businessFax
●
friendPhone
People • businessEmail
●
friendFax
Holiday list • BusinessURL
●
friendEmail
• Spouse
●
businessName
• Kids Name
●
businessContact
●
businessContactPos • birthday
© Kamruddin Nur 29
Address Book: Preliminary Attributes
Friends ●
friendName • businessPhone
Business ●
friendAddress • businessFax
People
●
friendPhone • businessEmail
●
friendFax
Holiday • BusinessURL
●
friendEmail
list • Spouse
●
businessName
• Kids Name
●
businessContact
●
businessContactPos • Birthday
• HolidayList
© Kamruddin Nur 30
Address Book: Entity & Attributes
Friends Businesses Addresses
friend1stName businessName friendStreet
friendLastName contact1Name friendCity
friendStreet contactLastName friendState
friendCity businessContactPos friendZIP
friendState businessStreet
friendZIP businessCity
friendAC businessState
friendPhoneNo businessZIP
friendFaxAC businessAC
friendFaxNo businessPhoneNo
friendEmail businessFaxAC
spouse businessFaxNo
kidnames businessEmail
birthMon businessURL
birthDay
holidayList
© Kamruddin Nur 31
Address Book: Entity & Attributes
Friends Businesses Addresses Telephones
friend1stName businessName street friendAC
friendLastName contact1Name city friendPhoneNo
friendAC contactLastName state
friendPhoneNo businessContactPos ZIP
friendFaxAC businessAC
friendFaxNo businessPhoneNo
friendEmail businessFaxAC
spouse businessFaxNo
kidnames businessEmail
birthMon businessURL
birthDay
holidayList
© Kamruddin Nur 32
Address Book: Entity & Attributes
Friends Businesses Addresses Telephones
friend1stName businessName street friendAC
friendLastName contact1Name city friendPhoneNo
friendAC contactLastName state phoneType
friendPhoneNo businessContactPos ZIP
friendFaxAC businessAC
friendFaxNo businessPhoneNo
friendEmail businessFaxAC
spouse businessFaxNo
kidnames businessEmail
birthMon businessURL
birthDay
holidayList
© Kamruddin Nur 33
Address Book: Entity & Attributes
Friends Businesses Addresses Telephones Kids
friend1stName businessName street AC kidnames
friendLastName contact1Name city phoneNo
friendEmail contactLastName state phoneType
spouse businessContactPos ZIP
kidnames businessEmail
birthMon businessURL
birthDay
holidayList
© Kamruddin Nur 34
Address Book: Entity & Attributes
Friends Businesses Addresses Telephones Kids
friend1stName businessName street AC kidnames
friendLastName contact1Name city phoneNo *kidKey
friendEmail contactLastName state phoneType
spouse businessContactPosZIP *phonekey
birthMon businessEmail *addkey
birthDay businessURL
holidayList *bkey
*fkey
© Kamruddin Nur 35
Address Book: Entities
Addresses
Kids Friends Businesses
Telephones
© Kamruddin Nur 36
Address Book: Entity Relationships
Addresses
Kids Friends Businesses
Telephones
© Kamruddin Nur 37
Address Book: Entity Relationships
Addresses
Kids Friends Businesses
Telephones
© Kamruddin Nur 38
Address Book: Entity Relationships
Addresses
Kids Friends Businesses
Telephones
© Kamruddin Nur 39
Address Book: Entity Relationships
Addresses
Kids Friends Businesses
Telephones
© Kamruddin Nur 40
Address Book: Entity Relationships
Addresses
Kids Friends Businesses
Telephones
© Kamruddin Nur 41
Address Book: Entity Relationships
Addresses
Kids Friends Businesses
Telephones
© Kamruddin Nur 42
Address Book: Entity Relationships
Addresses
Kids Friends Businesses
Telephones
© Kamruddin Nur 43
Address Book: Entity Relationships
are residences are locations
Addresses
have exist
live at at
Kids Friends Businesses
live with have have ring at
have
different
kinds
Telephones
contact ring at
© Kamruddin Nur 44
Address Book: Entity Relationships
Addresses
Kids Friends Businesses
Telephones
© Kamruddin Nur 45
Rules for Foreign Key Assignment
● One-to-one: Copy the primary key from the dominant table as a
foreign key as subordinate table.
● One-to-Many: Copy the primary key from the “One” side as the
foreign key into the “Many” side.
● Many-to-Many: Insert a third table between the two tables, and copy
the primary key from each table into the new third table. The only
field in this new table will be these foreign keys.
© Kamruddin Nur 46
Address Book: Entity Relationships
Friends Businesses Addresses Telephones Kids
friend1stName businessName street AC kidnames
friendLastName contact1Name city phoneNo *kidKey
friendEmail contactLastName state phoneType
spouse businessContactPos ZIP *phonekey
birthMon businessEmail *akey
birthDay businessURL +bkey
holidayList *bkey
*fkey
© Kamruddin Nur 47
Address Book: Entity Relationships
Addresses
Kids Friends Businesses
Telephones
© Kamruddin Nur 48
Address Book: Entity Relationships
Friends Businesses Addresses Telephones Kids
friend1stName businessName street AC kidnames
friendLastNam contact1Name city phoneNo *kidKey
e contactLastName state phoneType
friendEmail businessContactPos ZIP *phonekey
spouse businessEmail *akey +bkey
birthMon businessURL +bkey
birthDay *bkey
holidayList
*fkey
© Kamruddin Nur 49
Address Book: Entity Relationships
Addresses
Kids Friends Businesses
Telephones
© Kamruddin Nur 50
Address Book: Entity Relationships
Friends Businesses Addresses Telephones Kids
friend1stName businessName street AC kidnames
friendLastNam contact1Name city phoneNo *kidKey
e contactLastName state phoneType
friendEmail businessContactPos ZIP *phonekey
spouse businessEmail *akey +bkey
birthMon businessURL +bkey +akey
birthDay *bkey
holidayList
*fkey
© Kamruddin Nur 51
Address Book: Entity Relationships
Addresses
Kids Friends Businesses
Telephones
© Kamruddin Nur 52
Address Book: Entity Relationships
Friends/Kids Addresses
Kids Friends Businesses
Telephones
© Kamruddin Nur 53
Address Book: Entity Relationships
Friends Businesses Addresses Telephones Kids
friend1stName businessName street AC kidnames
friendLastNam contact1Name city phoneNo *kidKey
e contactLastName state phoneType
friendEmail businessContactPos ZIP *phonekey
spouse businessEmail *akey +bkey
birthMon businessURL +bkey +akey
birthDay *bkey
holidayList
*fkey
Friends/Kids
+fkey
+kidKey
© Kamruddin Nur 54
Address Book: Entity Relationships
Friends/Kids Addresses
Kids Friends Businesses
Telephones
© Kamruddin Nur 55
Address Book: Entity Relationships
Friends/
Addresses
Friends/Kids Addresses
Kids Friends Businesses
Friends/ Telephones
Telephones
© Kamruddin Nur 56
Address Book: Entity Relationships
Friends Businesses Addresses Telephones Kids
friend1stName businessName street AC kidnames
friendLastNam contact1Name city phoneNo *kidKey
e contactLastName state phoneType
friendEmail businessContactPos ZIP *phonekey
spouse businessEmail *akey +bkey
birthMon businessURL +bkey +akey
birthDay *bkey
holidayList
*fkey
Friends/Kids Friends/Telephones Friends/Addresses
+fkey +fkey +fkey
+kidKey +phonekey +akey
© Kamruddin Nur 57
Summary
From this lecture we have learned the details of
Entities, attributes, relationships
Different types of attributes
Different Multiplicity constraints on entity relationships
How to find entities, attributes, relationships
How to deal with one-to-one, one-to-many, many-to-many
relationships
How to find primary and foreign keys
© Kamruddin Nur 58