3ERMODEL
-
Upload
anshu-kumar -
Category
Documents
-
view
215 -
download
0
description
Transcript of 3ERMODEL
-
Database Design ProcessDatabaseRequirementsConceptual DesignConceptualModelLogical DesignPhysical DesignLogicalSchemaE-R ModelingChoice of aDBMSData ModelMapping
Database Systems
-
Entity-Relationship ModelAn entity is a collection of real-world objects that have many common properties.Examples: Students, Instructors, Courses, SectionsStudent entities have properties: name, address, major, graduation-yearA student may be John Smith, 22 Sage Rd., Computer Science, 2000An attribute is a data item that describes a property of an entity
Database Systems
-
EntitiesStudentssidstudent_namemid_initialfirstnamelastnamehobbiesprimary identifiermulti valued attributecomposite attribute
Database Systems
-
Mapping Entities to RelationsEach entity in an E-R model is mapped to a separate relationthe primary identifier is mapped to the primary key (underlined!)all regular attributes are mapped to an attribute in the tableeach subpart of a composite attribute is mapped to a different attributeeach multi-valued attributed is mapped to a separate relation that inherits the primary key of the parent relation
Database Systems
-
Mapping EntitiesStudentssidstudent_namemid_initialfirstnamelastnamehobbiesStudents( sid, lastname, firstname, mid_initial )
Hobbies( sid, hobby )Foreign key sid referencesthe Students relation!
Database Systems
-
Map the Auction EntitiesOwnersoidowner_namemid_initialfirstnamelastnameemailphone#itemsoldBuyersbuyidbuyer_nameemailphonecc_numaddressstreetcitystatezip
Database Systems
-
Map the Auction EntitiesItemsiidnamelocationdescriptionBidsbidamountdate/timedatetime
Database Systems
-
RelationshipsGiven a set of entities E1,E2,,Ek, a relationship R defines a rule of correspondence between these entities.An instance r(e1,e2,,ek) of the R relation means entities e1,e2,,ek are in a relation r at this instance.If two people are married, they are in a relationship:married(Bob, Margaret)If a student A takes a course C offered by professor B, then A,B,C are in a relationship.
Database Systems
-
RelationshipsItemsBuyersBidsplaceownOwnersacceptdatebinary relationshipternary relationship
Database Systems
-
Cardinalities of RelationshipsParticipation cardinalities of a relationship R for an entity E are:min-card(E, R) : the minimum number of entities in E that should be mapped via Rmax-card(E, R): the maximum number of entities in E that can be mapped via ROwn is a relation between owner and itemShould each owner be selling items?How many items can an owner sell?
Database Systems
-
Cardinalities of RelationshipsE R FE R FE R FOne-to-one relationshipmin-card(E, R)=0max-card(E,R)=1min-card(F,R)=0max-card(F,R)=1Many-to-one relationshipmin-card(E, R)=0max-card(E,R)=Nmin-card(F,R)=1max-card(F,R)=1Many-to-many relationshipmin-card(E, R)=0max-card(E,R)=Nmin-card(F,R)=0max-card(F,R)=N
Database Systems
-
CardinalitiesItemsBuyersBidsplaceownOwnersacceptdate(1,1)(0,N)(0,N)(0,1)(0,N)(1,1)(0,N)
Database Systems
-
CardinalitiesIf max-card(E,R)=1 then E has single-valued participation in RIf max-card(E,R)=N then E has multi-valued participation in RGiven a binary relation R between E and F, R is said to beone-to-one if both E and F have single-valued participationone-to-many if E has single and F has multi-valued participationmany-to-many if both E and F have multi-valued participation
Database Systems
-
Mapping Relationships to RelationsMap one-to-one and one-to-many (or many-to-one) relationships into the existing relations (derived from entities)If E-R-F is one-to-many, then include the primary key of the relation for F in the relation for E.If E-R-F is one-to-one, then include key for E in F, or the key for F in E.If E-R-F is many-to-many, create a new relation for R that has the primary keys for both E and F.If R has attributes, migrate them to the relation with the foreign keys!Contains Foreign Key(s)
Database Systems
-
Mapping the Auction DatabaseOwners( oid, itemsold, lastname, firstname, mid_initial, phone )
OwnerEmail( oid, email )
Buyers( buyid, buyername, ccnum,street, state, city, zip, phone )
BuyerEmail( buyid, email )
Items( iid, name, location, description, oid )
Bids( bid, date, time, amount, acceptingoid, acceptdate, buyid, iid )
Database Systems
-
CardinalitiesItemsBuyersBidsplaceownOwnersacceptdate(1,1)(0,N)(0,N)(0,1)(0,N)(1,1)(0,N)
Database Systems
-
ProblemConsider the design of a database to manage airline reservations:For flights, it contains the departure and arrival airports, dates and timesFor flights, it also contains a number of different pricing plans with different conditions (Saturday stay, advance booking, etc.)For passengers, it contains the name, telephone number and seat type preferenceReservations include the seat assigned to a passengerPassengers can have multiple reservations
Database Systems
-
Solutionairportflightpassengerdepartarrivedatedatetimetimereservationseatpricing plannameconditionsnamephoneseat pref(0,N)(0,N)(0,N)(0,N)(1,1)(1,1)
Database Systems
-
Entity Relationship ModelEntities play different roles in a relationshipEmployeessupervisesSupervised-by(1, 1)Supervisor-of(0, N)Employeessupervisessupervised(0, N)Projectsemployee-supervisor(1, 1)project-supervisor(1, N)Recursiverelationshipeid
Database Systems
-
Entity Relationship ModelMany-to-many relationships are translated into new relationsItemsBuyersStoresbuy(0,N)(0,N)(0,N)amount
Database Systems
BUY
Item
Buyer
Store
Amount
I1
B1
S1
3
I2
B1
S2
4
I3
B4
S1
5
I2
B5
S2
2
-
Entity Relationship ModelTernary relationships may be represented by binary relationshipsItemsBuyersStoresbuy_from(0,N)buy_itemsell_item(0,N)(0,N)(0,N)(0,N)(0,N)Is this conceptuallyequivalent to the previous ternaryrelationship?
Database Systems
-
Weak EntitiesThe existence of a weak entity W depends on the existence of another (strong) entity E through a relationship R.(Alternate) Two different weak entities may have the same identity (key) if they are related to two different strong entities.BranchBankhas(0,N)(1,1)namenumberaddress
Database Systems
-
Weak EntitiesWeak entities can be mapped to the relational model by:Map each weak entity E that depends on a strong entity F to a new relation RRelation R contains all the attributes in E and the primary key of FThe primary key for R is the primary key of E and the primary key of F
Database Systems
-
Generalization HierarchiesLower items inherit attributes of their parentsConcertsdateClassicalpiecesconductorsoloistsOtherperformerslocationorchestraOption 1. Translate intoa single relation with a flag for the type of entity[many null values]
Option 2. Translate into three entities and two is-a relationships, then translate the resulting graph.
Database Systems
-
ExtensionsAll relational DBMSs come with extensions that give more flexibility to the DBAExamples from Informixcomposite attributes -> translate as a record address of type ROW(street string, city string, state string, zip string) multi-valued attributes -> translate into collection types such as sets, lists, multi-sets (bags)hierarchies -> create typed tables and translate into a type hierarchy.REMEMBER, the extensions complicate the data model and make certain SQL queries much harder or impossible, leaving the database programmer with a much harder job of maintaining the database!
Database Systems
Lecture 3 - Entity Relationship Model