DBMS-Unit II
DBMS-Unit II
ystem n
i
ERModel
Concept:
ERModelinghelpsyoutoanalyzedatarequirementssystematicallytoproduce a
well-designed database. So, it is considered a best practice to complete ER
modeling before implementing your database.
Entity-RelationshipDiagramAgraphicalrepresentationofentity-relationship
model. Alsocalled E-R diagramor just ERD.
o ERmodelstandsforanEntity-Relationshipmodel.Itisahigh-leveldatamodel. Thismodelisusedto
definethedataelementsandrelationship for aspecified system.
o Itdevelopsaconceptualdesignforthedatabase.Italsodevelopsaverysimple and easy to design
view of data.
o In ER modeling, the database structure is portrayed as a diagram called an entity-relationship
diagram.
Forexample,Supposewedesignaschooldatabase.Inthisdatabase,thestudentwill
beanentitywithattributeslikeaddress,name,id,age,etc.Theaddresscanbeanother
entitywithattributeslikecity,streetname,pincode,etcandtherewillbearelationship between them.
Prof.Akshata 1
DatabaseManagementS U
ystem n
i
ComponentofERDiagram
Prof.Akshata 2
DatabaseManagementS U
ystem n
i
1. Entity:
Anentitymaybeanyobject,class,personorplace.IntheERdiagram,anentitycanbe
represented as rectangles.
a. WeakEntity
Anentitythatdependsonanotherentitycalledaweakentity.Theweakentitydoesn't contain
any key attribute of its own. The weak entity is represented by a double rectangle.
b. StrongEntity
Asinglerectangleisusedforrepresentingastrongentityset.
Adiamondsymbolisusedforrepresentingtherelationshipthatexistsbetween two
strong entity sets.
Asinglelineisusedforrepresentingtheconnectionofthestrongentityset with the
relationship set.
Adoublelineisusedforrepresentingthetotalparticipationofanentityset with the
relationship set.
Total participation mayormaynotexistintherelationship
Example-
ConsiderthefollowingERdiagram-
Prof.Akshata 3
DatabaseManagementS U
ystem n
i
InthisERdiagram,
Twostrongentitysets“Student”and“Course”arerelatedtoeachother.
• StudentIDandStudentnamearetheattributesofentityset “Student”.
• StudentIDistheprimarykeyusingwhichanystudentcanbeidentified
uniquely.
• CourseIDandCoursenamearetheattributesofentityset“Course”.
• CourseIDistheprimarykeyusingwhichanycoursecanbeidentified
uniquely.
• DoublelinebetweenStudentandrelationshipsetsignifiestotalparticipation.
• Itsuggeststhateachstudentmustbeenrolledinatleastonecourse
• SinglelinebetweenCourseandrelationshipsetsignifiespartialparticipation.
• Itsuggeststhattheremightexistsomecoursesforwhichnoenrollmentsare made
2. Attribute
Theattributeisusedtodescribethepropertyofanentity.Eclipseisusedtorepresent an
attribute.
Forexample,id,age,contactnumber,name,etc.canbeattributesofastudent.
Prof.Akshata 4
DatabaseManagementS U
ystem n
i
a. KeyAttribute
Thekeyattributeisusedtorepresentthemaincharacteristicsofanentity.Itrepresents a
primary key. The key attribute is represented by an ellipse with the text underlined.
b. CompositeAttribute
Anattributethatcomposedofmanyotherattributesisknownasacompositeattribute.
Thecompositeattributeisrepresentedbyanellipse,andthoseellipsesareconnected with
an ellipse.
Prof.Akshata 5
DatabaseManagementS U
ystem n
i
c. MultivaluedAttribute
Anattributecanhavemorethanonevalue.Theseattributesareknownasa multivalued
attribute. The double oval is used to represent multivalued attribute.
Forexample,astudentcanhavemorethanonephonenumber.
d. DerivedAttribute
An attribute that can be derived from other attribute is known as aderived attribute.It
can be represented by a dashed ellipse.
Prof.Akshata 6
DatabaseManagementS U
ystem n
i
3. Relationship
Typesofrelationshipareasfollows:
a. One-to-OneRelationship
Whenonlyoneinstanceofanentityisassociatedwiththerelationship,thenitisknown as one
to one relationship.
Forexample,Afemalecanmarrytoonemale,andamalecanmarrytoonefemale.
Prof.Akshata 7
DatabaseManagementS U
ystem n
i
b. One-to-manyrelationship
When only one instance of the entity on the left, and more than one instance of an
entityontherightassociateswiththerelationshipthenthisisknownasaone-to-many
relationship.
For example,Scientist can invent many inventions, but the invention is done by the
only specific scientist.
c. Many-to-onerelationship
When more than one instance of the entity on the left, and only one instance of an
entity on the right associates with the relationship then it is known as a many-to-one
relationship.
For example,Student enrolls for only one course, but a course can have many
students.
d. Many-to-manyrelationship
For example,Employee can assign by many projects and project can have many
employees.
Prof.Akshata 8
DatabaseManagementS U
ystem n
i
EntityTypesandEntitySets
Prof.Akshata 9
DatabaseManagementS U
ystem n
i
Figureshowstwoentitytypes:EMPLOYEEandCOMPANY,andalistofsomeof the
attributes for each
Intension(entitytypedescribestheschema)
Extensionoftheentitytype(collectionofentitiesofaparticularentitytype grouped
into an entity set)
Prof.Akshata 1
DatabaseManagementS U
ystem n
i
Entitytypedefinesacollection(orset)ofentitythathavesameattributes.
Eachentitytypeinthedatabaseisdescribedbyitsnameandattributes.
Entitysetisthecollectionofallentitiesofaparticularentitytypeina database at
any point in time.
Theentitysetusuallyreferredtousingthesamenameastheentitytype.
Entity type describes schema or intension for set entities that share same
structure
Entitytypedefineasetofentitiesthathavethesameattributes.
Entities with the same basic attributes are grouped or typed into an entity
type.
o Forexample,theentitytypeEMPLOYEEandPROJECT.
Prof.Kavita 1
DatabaseManagementS U
ystem n
i
Attribute
Theattributeisusedtodescribethepropertyofanentity.Eclipseisusedtorepresent an
attribute.
Forexample,id,age,contactnumber,name,etc.canbeattributesofastudent.
ThebasicobjectthattheERmodelrepresentsisanentity,
Entity-
whichisathingintherealworldwithanindependentexistence.Anentitymaybeanobj
ectwithaphysicalexistence(forexample,aparticularperson,car, house, or
employee) or it may be an object with a conceptual existence (for instance, a
company, a job, or a university course)
Each entity has attributes—the particular properties that describe it. For
example,anEMPLOYEEentitymaybedescribedbytheemployee’sname,age,
address, salary, and job.
Aspecificentitywillhaveavalueforeachofitsattributes.Forexampleaspecific
employeeentitymayhaveName='JohnSmith',SSN='123456789',Address
='731,Fondren,Houston,TX',Sex='M', BirthDate='09-JAN-55‘
Each attribute has a value set (or data type) associated with it – e.g. integer,
string, subrange, enumerated type, …
Prof.Kavita 1
DatabaseManagementS U
ystem n
i
AttributeTypes:
SimpleorAtomicAttribute
CompositeAttributes
Single-Valued
MultiValued
StoredAttribute
DerivedAttribute
SimpleorAtomicAttribute
Eachentityhasasingleatomicvaluefortheattribute
AtomicAttributeisanattributethatisnotdivisible.
CalledAtomicorSimpleAttributes.
Example
Prof.Kavita 1
DatabaseManagementS U
ystem n
i
CompositeAttributes:
Theattributemaybecomposedofseveralcomponents
ExampleofCompositeAttribute
Prof.Kavita 1
DatabaseManagementS U
ystem n
i
Single-ValuedVSMultiValuedAttributes:
Single-Valued:attributehasasinglevalueforaparticularentity
An attribute can have more than one value. These attributes are known as a
multivalued attribute. The double oval is used to represent multivalued
attribute.
MultiValueAttribute:Anentitymayhavemultiplevaluesforthatattribute
ColorofaCARorPreviousDegreesofaSTUDENT.
Denotedas{Color}or{PreviousDegrees}.
Prof.Kavita 1
DatabaseManagementS U
ystem n
i
StoredVSDerivedAttributed:
An attribute that can be derived from other attribute is known as aderived attribute.It
can be represented by a dashed ellipse.
For a particular person entity, the value of Age can be determined from the
current (today’s) date and the value of that person’s Birthdates.
TheAgeattributeishencecalledaderivedattributeandissaidtobederivable from
the Birth_date attribute, which is called a stored attribute.
The value of certain attributes cannot be obtained form some other attributes,
they can not be derived such attributes are said to be stored attribute
Some attribute values can be derived from related entities; for example, an
attribute Number_of_employees of a EPARTMENT entity can be derived by
counting the number of employees related to (working for) that department.
Key Attribute:
Prof.Kavita 1
DatabaseManagementS U
ystem n
i
Animportantconstraintontheentitiesofanentitytypeisthekeyor
uniqueness constrainton attributes.
An entity type usually has one or more attributes whose values are distinct for
each individual entity in the entity set. Such an attribute is called a key
attribute, and its values can be used to identify each entity uniquely.
Forexample,theNameattributeisakeyoftheCOMPANYentitytypebecause no
two companies are allowed to have the same name.
Prof.Kavita 1
DatabaseManagementS U
ystem n
i
Relationship
Arelationshipisanassociationamongtwoormoreentities.Arelationshipcaptures two or
more entities are related to one another. Relationship can be thought of as verb
linking two or more nouns
E.g.studentRameshenrolsinDiscreteMathematicscourse•
RelationshipenrolshasStudentandCourseastheparticipatingentitysets
An“owns”iecompanyandcomputer
A“supervises”betweenempanddepartment
“performs”betweenartist andasong
“proved”betweenmathematicianandtheorem
Typesofrelationshipareasfollows:
a. One-to-OneRelationship
Prof.Kavita 1
DatabaseManagementS U
ystem n
i
Whenonlyoneinstanceofanentityisassociatedwiththerelationship,thenitisknown as one
to one relationship.
Forexample,Afemalecanmarrytoonemale,andamalecanmarrytoonefemale.
b. One-to-manyrelationship
When only one instance of the entity on the left, and more than one instance of an
entityontherightassociateswiththerelationshipthenthisisknownasaone-to-many
relationship.
For example,Scientist can invent many inventions, but the invention is done by the
only specific scientist.
c. Many-to-onerelationship
When more than one instance of the entity on the left, and only one instance of an
entity on the right associates with the relationship then it is known as a many-to-one
relationship.
For example,Student enrolls for only one course, but a course can have many
students.
Prof.Kavita 1
DatabaseManagementS U
ystem n
i
d. Many-to-manyrelationship
Prof.Kavita 1
DatabaseManagementS U
ystem n
i
When morethan oneinstanceoftheentityon theleft, and morethan oneinstanceof an
entity on the right associates with the relationship then it is known as a many-to-
many relationship.
For example,Employee can assign by many projects and project can have many
employees.
DegreeofARelationship:
Thenumberofentitysetsthatparticipateinarelationshipsetistermedasthe degree of that
relationship set. Thus
BothMANAGESandWORKS_ONarebinaryrelationships.
An exampleofa ternaryrelationshipis SUPPLY, Therelationship‘Supplies’ is
usedtorecordthespecificPARTssuppliedbyagivenVENDORtoaparticular
WAREHOUSE
Prof.Kavita 1
DatabaseManagementS U
ystem n
i
Unaryrelationship
Isbetweentheinstancesofasingleentitytype(alsocalledrecursive relationships)
‘Is_Married_To’isaone-to-onerelationshipbetweeninstancesofthePERSON
entity type
‘Manages’isaone-to-manyrelationshipbetweeninstancesoftheEMPLOYEE
entity type
Employee
Supervisor1 NSupervisee
Supervisio
n
Prof.Kavita 2
DatabaseManagementS U
ystem n
i
Binaryrelationships:
The degree of a relationship type is the number of participating entity types.
Meaning if the relationship is between two entity types (Employee and
Department), then the relationship is binary, or has a degree of two.
Between the instances of two entity types, and is the most common type of
relationshipencounteredindatamodelling.e.g.(one-to-one)anEMPLOYEEis
assigned one PARKING_PLACE, and each PARKING_PLACE is assigned to one
EMPLOYEE
e.g.(onetomany)aPRODUCT_LINEmaycontainmanyPRODUCTS,andeach
PRODUCTbelongstoonlyonePRODUCT_LINE
e.g.(many-to-many)aSTUDENTmayregisterformorethanoneCOURSE,and
eachCOURSEmayhavemanySTUDENTS
Ternaryrelationships:
If the relationship is between three participating entities, it has a degree of
three, and therefore is a ternary relationship.
Prof.Kavita 2
DatabaseManagementS U
ystem n
i
4. N-aryRelationshipSet-
N-aryrelationshipsetisarelationshipsetwhere‘n’entitysetsparticipateinarelationship set
Cardinalty:
The cardinality ratio specifies the maximum number of relationship instances
that an entity can participate in.
The possible cardinality ratios for binary relationship types are: 1:1, 1:N, N:1,
M:N.
Prof.Kavita 2
DatabaseManagementS U
ystem n
i
Cardinality ratios are shown on ER diagrams by displaying 1, M and N on the
diamonds.
Theratioshownclosesttoanentity,representstheratiotheotherentityhasto that
entity.
Prof.Kavita 2
DatabaseManagementS U
ystem n
i
Onetoone(1:1)
Prof.Kavita 2
DatabaseManagementS U
ystem n
i
In a one-one relationship, each entity of either entity set is related to at most
one entity of the other set.
One-to-ManyRelationship(1:N)
One-to-Manyrelationshipsoccurwhenasingleentityinstanceisrelatedto many
occurrences of a second entity.
Onecustomercanbeissuedwithmanyestimates(therelationshipisdescribed as
one-to-many)
Many-to-ManyRelationship(N:M)
Many-to-many relationships occur where many instances of an entity relate to
many instances of a second entity
Theserelationshipsusuallycontainahiddenentitywhichshouldbeextracted
Usually N:M relationships are broken into one or more pairs of one-to-
manyrelationships
Manyestimatesreferstomanystockitems(ormanystockitemsarereferredto by
many estimates)
Prof.Kavita 2
DatabaseManagementS U
ystem n
i
Manytoone:
Prof.Kavita 2
DatabaseManagementS U
ystem n
i
Areverserelationofonetomany
WeakEntityTypes:
Entitytypesthatdonothavekeyattributesarecalledweakentitytypes.
AWeakEntityhastodependonastrongentityforitsexistence.So,itcreates a total
participation in the identifying relationship.
Entities that belong to a weak entity type are identified by being related to
specific entities from another entity type in combination with one of their
attribute values.
Thisentitytypeiscalledanidentifyingorownerentity type.
Forexample,letsassumeinalibrarydatabase,wehaveanentitytypeBook.For each
book, we keep track of the author, ISBN, and title. The library may own
several copiesof thesamebook, andforeachcopy,itkeeps track ofthecopy
number (a different copy number for each copy of a given book) and price of
each copy.
Not all existence dependencies result in a weak entity type; if an entity has a
key attribute then it is not a weak entity.
Prof.Kavita 2
DatabaseManagementS U
ystem n
i
A weak entity type usually has a partial key, which is the set of attributes that
canuniquelyidentifyweakentitiesthatarerelatedtothesameownerentity.
Example:
o ADEPENDENTentityisidentifiedbythedependent’sfirstname,andthe
specificEMPLOYEEwithwhomthedependentisrelated
o NameofDEPENDENTisthepartialkey
Prof.Kavita 2
DatabaseManagementS U
ystem n
i
o DEPENDENTisaweakentitytype
o EMPLOYEE is its identifying entity type via the identifying relationship
typeDEPENDENT_OF
E-RDiagram
ER Diagramstands for Entity Relationship Diagram, also known as ERD is a
diagram that displays the relationship of entity sets stored in a database. In other
words,ERdiagramshelptoexplainthelogicalstructureofdatabases.ERdiagramsare
created based on three basic concepts: entities, attributes and relationships.
AnEntity–relationshipmodel(ERmodel)describesthestructureofadatabase
with the help of a diagram, which is known as Entity Relationship Diagram
(ER Diagram).
AnERmodelisadesignorblueprintofadatabasethatcanlaterbeimplemented
asadatabase.ThemaincomponentsofE-Rmodelare:entitysetandrelationship set.
AnERdiagramshowstherelationshipamongentitysets.Anentitysetisagroup of
similar entities and these entities can have attributes.
In terms of DBMS, an entity is a table or attribute of a table in database, so by
showing relationship among tables and their attributes, ER diagram shows the
complete logical structure of a database.
AsimpleERDiagram:
• In the following diagram we have two entities Student and College and their
relationship.
• The relationship between Student and College is many to one as a college can
have many students however a student cannot study in multiple colleges at the
same time.
• StudententityhasattributessuchasStu_Id,Stu_Name&Stu_Addrand
College entity has attributes such as Col_ID & Col_Name
Prof.Kavita 2
DatabaseManagementS U
ystem n
i
NotationsofE-RDiagram:
NamingConventionsandDesignAspects
Prof.Kavita 2
DatabaseManagementS U
ystem n
i
thebasicdesignissuesofanERdatabaseschemainthefollowingpoints:
1) UseofEntitySetvsAttributes
• The use of an entity set or attribute depends on the structure of the real-
worldenterprisethatisbeingmodelledandthesemanticsassociatedwithitsattributes.
• Itleadstoamistakewhentheuserusetheprimarykeyofanentitysetasan attribute of
another entity set.
• Instead,heshouldusetherelationshiptodoso.Also,theprimarykey attributes are
implicit in the relationship set, but we designate it in the relationship sets.
2) UseofEntitySetvs.RelationshipSets
• It is difficult to examine if an object can bebest expressed by an entity set
orrelationship set.
• Tounderstandanddeterminetherightuse,theuserneedtodesignatea relationship set
for describing an action that occurs in-between the entities.
• If there is a requirement of representing the object as a relationship set, then its
better not to mix it with the entity set.
3) UseofBinaryvsn-aryRelationshipSets
• Generally, the relationships described in the databases are binary relationships.
However, non-binary relationships can be represented by several binary
relationships.
• Forexample,wecancreateandrepresentaternaryrelationship'parent'thatmay relate
to a child, his father, as well as his mother. Such relationship can also be
representedbytwobinaryrelationshipsi.e,motherandfather,thatmayrelateto their
child.
• Thus,itispossibletorepresentanon-binaryrelationshipbyasetofdistinct binary
relationships.
4) PlacingRelationshipAttributes
• The cardinality ratios can become an affective measure in the placement of the
relationship attributes.
• So, it is better to associate the attributes of one-to-one or one-to-many
relationshipsetswithanyparticipatingentitysets,insteadofanyrelationshipset.
• Thedecisionofplacingthespecifiedattributeasarelationshiporentityattribute
should possess the characteristics of the real world enterprise that is being
modelled.
• For example, if there is an entity which can be determined by the combination
of participating entity sets, instead of determine it as a separate entity.
• Such type of attribute must be associated with the many-to-many relationship
sets.
• Thus,itrequirestheoverallknowledgeofeachpartthatisinvolvedinbdesigning and
modelling an ER diagram.
Prof.Kavita 2
DatabaseManagementS U
ystem n
i
• Thebasicrequirementistoanalysesthereal-worldenterpriseandtheconnectivity of
one entity or attribute with other.
SomeexamplesofERDiagram:
1.SchoolManagementsERModel
Prof.Kavita 2
DatabaseManagementS U
ystem n
i
Prof.Kavita 3
DatabaseManagementS U
ystem n
i
Prof.Kavita 3