ER Diagram introduction .ppt

sivamathi12 92 views 39 slides Jul 21, 2024
Slide 1
Slide 1 of 39
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28
Slide 29
29
Slide 30
30
Slide 31
31
Slide 32
32
Slide 33
33
Slide 34
34
Slide 35
35
Slide 36
36
Slide 37
37
Slide 38
38
Slide 39
39

About This Presentation

.


Slide Content

Entity Relationship Model

Entity Relationship Model
•AnEntityRelationshipDiagram(ERD)isavisual
representationofdifferentdatausingconventionsthat
describehowthesedataarerelatedtoeachother.
•Forexample,theelementswriter,novel,andconsumermaybe
describedusingERdiagramsthisway:
Theelementsinsiderectanglesare
calledentitieswhiletheitemsinside
diamondsdenotetherelationships
betweenentities.

Entity
•Anentitycanbeareal-worldobject,eitheranimateorinanimate,
thatcanbeeasilyidentifiable.
–Forexample,inaschooldatabase,students,teachers,
classes,andcoursesofferedcanbeconsideredasentities.
–Alltheseentitieshavesomeattributesorpropertiesthatgive
themtheiridentity.
•Anentitysetisacollectionofsimilartypesofentities.
–Anentitysetmaycontainentitieswithattributesharing
similarvalues.
–Forexample,
–aStudentssetmaycontainallthestudentsofaschool;
–likewiseaTeacherssetmaycontainalltheteachersofaschool
fromallfaculties.Entitysetsneednotbedisjoint.

Weak Entity
•Aweakentityisanentitythatdependsontheexistenceof
anotherentity.
•Inmoretechnicaltermsitcandefinedasanentitythatcannotbe
identifiedbyitsownattributes.
•Itusesaforeignkeycombinedwithitsattributedtoformthe
primarykey.
•Anentitylikeorderitemisagoodexampleforthis.
–Theorderitemwillbemeaninglesswithoutanordersoit
dependsontheexistenceoforder.

Attributes
•Entitiesarerepresentedbymeansoftheirproperties,
calledattributes.
•Allattributeshavevalues.
•Forexample,astudententitymayhavename,class,
andageasattributes.
•Thereexistsadomainorrangeofvaluesthatcanbe
assignedtoattributes.
•Forexample,astudent'snamecannotbeanumeric
value.Ithastobealphabetic.Astudent'sagecannot
benegative,etc.

Types of Attributes
•Simpleattribute−Simpleattributesareatomicvalues,which
cannotbedividedfurther.Forexample,astudent'sphone
numberisanatomicvalueof10digits.
•Compositeattribute−Compositeattributesaremadeofmore
thanonesimpleattribute.Forexample,astudent'scomplete
namemayhavefirst_nameandlast_name.

Types of Attributes (contd.,)
•Derivedattribute−Derivedattributesaretheattributesthatdonotexistin
thephysicaldatabase,buttheirvaluesarederivedfromotherattributes
presentinthedatabase.
•Forexample,average_salaryinadepartmentshouldnotbesaveddirectlyin
thedatabase,insteaditcanbederived.
•Foranotherexample,agecanbederivedfromdata_of_birth.
•Forexampleforacircletheareacanbederivedfromtheradius.

Types of Attributes (contd.,)
•Single-valueattribute−Single-valueattributescontainsingle
value.Forexample−Social_Security_Number.
•Multi-valueattribute−Multi-valueattributesmaycontainmore
thanonevalues.Forexample,apersoncanhavemorethanone
phonenumber,email_address,etc.
•Forexampleateacherentitycanhavemultiplesubjectvalues.

•These attribute types can come together in a
way like −
•simple single-valued attributes
•simple multi-valued attributes
•composite single-valued attributes
•composite multi-valued attributes

Entity-Set and Keys
•Keyisanattributeorcollectionofattributesthatuniquely
identifiesanentityamongentityset.
•Forexample,theroll_numberofastudentmakeshim/her
identifiableamongstudents.
•SuperKey−Asetofattributes(oneormore)thatcollectively
identifiesanentityinanentityset.
•CandidateKey−Aminimalsuperkeyiscalledacandidatekey.An
entitysetmayhavemorethanonecandidatekey.
•PrimaryKey−Aprimarykeyisoneofthecandidatekeyschosen
bythedatabasedesignertouniquelyidentifytheentityset.

Relationship
•Theassociationamongentitiesiscalledarelationship.
•Forexample,anemployeeworks_atadepartment,a
studentenrollsinacourse.
•Here,Works_atandEnrollsarecalledrelationships.
•Forexample,theentity“carpenter”mayberelatedtotheentity
“table”bytherelationship“builds”or“makes”.Relationships
arerepresentedbydiamondshapesandarelabeledusingverbs.

Degree of Relationship
•Thenumberofparticipatingentitiesina
relationshipdefinesthedegreeofthe
relationship.
•Binary=degree2
•Ternary=degree3
•n-ary=degree

Mapping Cardinalities
•Cardinalitydefinesthenumberofentitiesinoneentityset,which
canbeassociatedwiththenumberofentitiesofothersetvia
relationshipset.
•One-to-one−OneentityfromentitysetAcanbeassociatedwith
atmostoneentityofentitysetBandviceversa.

•One-to-many−OneentityfromentitysetAcanbeassociated
withmorethanoneentitiesofentitysetBhoweveranentity
fromentitysetB,canbeassociatedwithatmostoneentity.

•Many-to-one−MorethanoneentitiesfromentitysetAcan
beassociatedwithatmostoneentityofentitysetB,however
anentityfromentitysetBcanbeassociatedwithmorethan
oneentityfromentitysetA.

•Many-to-many− One entity from A can be associated with
more than one entity from B and vice versa.

ER Diagram Representation
•LetusnowlearnhowtheERModelisrepresentedbymeansof
anERdiagram.
•Anyobject,forexample,entities,attributesofanentity,
relationshipsets,andattributesofrelationshipsets,canbe
representedwiththehelpofanERdiagram.

Entity
•Entitiesarerepresentedbymeansofrectangles.
Rectanglesarenamedwiththeentitysetthey
represent.

Attributes
•Attributesarethepropertiesofentities.Attributesare
representedbymeansofellipses.
•Everyellipserepresentsoneattributeandisdirectly
connectedtoitsentity(rectangle).

•Iftheattributesarecomposite,theyarefurtherdividedina
treelikestructure.Everynodeisthenconnectedtoits
attribute.Thatis,compositeattributesarerepresentedby
ellipsesthatareconnectedwithanellipse.

•Multivaluedattributes are depicted by double
ellipse.

•Derivedattributes are depicted by dashed ellipse.

Relationship
•Relationshipsarerepresentedbydiamond-shapedbox.
•Nameoftherelationshipiswritteninsidethediamond-box.
•Alltheentities(rectangles)participatinginarelationship,are
connectedtoitbyaline.
•BinaryRelationshipandCardinality
•Arelationshipwheretwoentitiesareparticipatingiscalledabinary
relationship.Cardinalityisthenumberofinstanceofanentityfrom
arelationthatcanbeassociatedwiththerelation.

•One-to-one−Whenonlyoneinstanceofanentityis
associatedwiththerelationship,itismarkedas'1:1'.The
followingimagereflectsthatonlyoneinstanceofeachentity
shouldbeassociatedwiththerelationship.Itdepictsone-to-
onerelationship.

•One-to-many−Whenmorethanoneinstanceofanentityis
associatedwitharelationship,itismarkedas'1:N'.The
followingimagereflectsthatonlyoneinstanceofentityon
theleftandmorethanoneinstanceofanentityontheright
canbeassociatedwiththerelationship.Itdepictsone-to-
manyrelationship.

•Many-to-one−Whenmorethanoneinstanceofentityis
associatedwiththerelationship,itismarkedas'N:1'.The
followingimagereflectsthatmorethanoneinstanceofan
entityontheleftandonlyoneinstanceofanentityontheright
canbeassociatedwiththerelationship.Itdepictsmany-to-one
relationship.

•Many-to-many−Thefollowingimagereflectsthatmorethan
oneinstanceofanentityontheleftandmorethanone
instanceofanentityontherightcanbeassociatedwiththe
relationship.Itdepictsmany-to-manyrelationship.

•Participation Constraints
•Total Participation− Each entity is involved in the relationship.
Total participation is represented by double lines.
•Partial participation− Not all entities are involved in the
relationship. Partial participation is represented by single lines.

Generalization Aggregation
•The ER Model has the power of expressing database entities in a conceptual
hierarchical manner.
•As the hierarchy goes up, it generalizes the view of entities, and as we go
deep in the hierarchy, it gives us the detail of every entity included.
•Going up in this structure is calledgeneralization, where entities are
clubbed together to represent a more generalized view.
•For example, a particular student named Mira can be generalized along with
all the students.
•The entity shall be a student, and further, the student is a person. The
reverse is called specializationwhere a person is a student, and that student
is Mira.

Generalization
•Theprocessofgeneralizingentities,wherethegeneralizedentitiescontain
thepropertiesofallthegeneralizedentities,iscalledgeneralization.
•Ingeneralization,anumberofentitiesarebroughttogetherintoone
generalizedentitybasedontheirsimilarcharacteristics.Forexample,
pigeon,housesparrow,crowanddovecanallbegeneralizedasBirds.

Specialization
•Specializationistheoppositeofgeneralization.In
specialization,agroupofentitiesisdividedinto
sub-groupsbasedontheircharacteristics.
•Takeagroup‘Person’forexample.Apersonhas
name,dateofbirth,gender,etc.These
propertiesarecommoninallpersons,human
beings.Butinacompany,personscanbe
identifiedasemployee,employer,customer,or
vendor,basedonwhatroletheyplayinthe
company.
•Similarly,inaschooldatabase,personscanbe
specializedasteacher,student,orastaff,based
onwhatroletheyplayinschoolasentities.

Inheritance
•We use all the above features of ER-
Model in order to create classes of
objects in object-oriented
programming.
•The details of entities are generally
hidden from the user; this process
known asabstraction.
•Inheritance is an important feature of
Generalization and Specialization. It
allows lower-level entities to inherit the
attributes of higher-level entities.
•For example, the attributes of a Person
class such as name, age, and gender can
be inherited by lower-level entities such
as Student or Teacher.

ER Diagram Example
•Suppose you are given the following requirements for a simple database for the
NationalHockey League (NHL):
•the NHL has many teams,
•each team has a name, a city, a coach, a captain, and a set of players,
•each player belongs to only one team,
•each player has a name, a position (such as left wing or goalie), a skill level, and
a setof injury records,
•a team captain is also a player,
•a game is played between two teams (referred to as host_teamand guest_team)
andhas a date (such as May 11th, 1999) and a score (such as 4 to 2).
•Construct a clean and concise ER diagram for the NHL database.

•Question 2:
•Auniversityregistrar’sofficemaintainsdataaboutthefollowing
entities:
•courses,includingnumber,title,credits,syllabus,and
prerequisites;
•courseofferings,includingcoursenumber,year,semester,section
number,instructor(s),timings,andclassroom;
•students,includingstudent-id,name,andprogram;
•instructors,includingidenti-cationnumber,name,department,
andtitle.
•Further,theenrollmentofstudentsincoursesandgrades
awardedtostudentsineachcoursetheyareenrolledformustbe
appropriatelymodeled.ConstructanE-Rdiagramforthe
registrar’sof-ce.Documentallassumptionsthatyoumakeabout
themappingconstraints.

•Question 3:
(a)Construct an E-R diagram for a car-insurance
company whose customers ownone or more cars
each. Each car has associated with it zero to any
number ofrecorded accidents.
(b)Construct appropriate tables for the above ER
Diagram ?

Car insurance tables:
•person (driver-id, name, address)
•car (license, year,model)
•accident (report-number, date, location)
•participated(driver-id, license, report-number,
damage-amount)
Tags