ExampleExample
BigHit Video Inc. wants to create an information system for online BigHit Video Inc. wants to create an information system for online sales of movies sales of movies in both DVD and videotape formatin both DVD and videotape format. People will be . People will be allowed to register as customers of the online site and to update allowed to register as customers of the online site and to update their stored information. Information must be maintained about their stored information. Information must be maintained about customers’ shipping addresses, e-mail addresses and credit cards. customers’ shipping addresses, e-mail addresses and credit cards. In a single sale, customers will be allowed to purchase any quantity In a single sale, customers will be allowed to purchase any quantity of videos. The items in a single sale will be shipped to a single of videos. The items in a single sale will be shipped to a single address and will have a single credit card charge.address and will have a single credit card charge.A customer will be provided with a virtual shopping cart to store A customer will be provided with a virtual shopping cart to store items to be purchased. As each item is selected, it is added to the items to be purchased. As each item is selected, it is added to the shopping cart. When the customer finishes shopping, he will be shopping cart. When the customer finishes shopping, he will be directed to a checkout area where payment and shipping directed to a checkout area where payment and shipping information is entered. Once the sale is complete, the customer will information is entered. Once the sale is complete, the customer will be sent a receipt by e-mail.be sent a receipt by e-mail.
ExampleExample
Entities:Entities:Customer (key: account , last name, first Customer (key: account , last name, first name, address, email, credit card, name, address, email, credit card, password)password)
Movie (key: id, title, genre, length)Movie (key: id, title, genre, length)
Sale (key: id, cost, date, credit card)Sale (key: id, cost, date, credit card)Shopping Cart (key: id, date)Shopping Cart (key: id, date)
ExampleExample
Relationship Relationship TypeType
Entity ClassEntity Class Entity ClassEntity Class Cardinality Cardinality RatioRatio
AttibutesAttibutes
PurchasesPurchases CustomerCustomer SaleSale one-to-one-to-manymany
IncludesIncludes SaleSale MovieMovie many-to-many-to-manymany
quantityquantity
SelectsSelects CustomerCustomer ShoppingCaShoppingCartrt
one-to-one-to-manymany
IncludesIncludes ShoppingCShoppingCartart
MovieMovie many-to-many-to-manymany
quantityquantity
Data Modeling with E-R DiagramData Modeling with E-R Diagram
An An Entity-RelationshipEntity-Relationship (E-R) model is a (E-R) model is a high-level conceptual modelhigh-level conceptual model
E-R models are best described using E-R models are best described using graphical diagramsgraphical diagrams
This model provides designers with an This model provides designers with an accurate and useful model that avoids accurate and useful model that avoids confusion and is understandable by usersconfusion and is understandable by users
E-R modelE-R model
An An E-R modelE-R model includes includes– Entity classesEntity classes– Attributes of each classAttributes of each class– Relationship types between classesRelationship types between classes– ConstraintsConstraints
Types of attributesTypes of attributesDesignation of key attributesDesignation of key attributesCardinalities of relationship typesCardinalities of relationship types
An E-R Model is typically represented An E-R Model is typically represented graphicallygraphicallyusing anusing an E-R diagram E-R diagram
E-R modelE-R model
E-R models cannot describe everything in the E-R models cannot describe everything in the real-world applicationreal-world application
Not all information about the attributes appears Not all information about the attributes appears in the E-R diagram. Most of the information is in the E-R diagram. Most of the information is maintained in the data dictionary maintained in the data dictionary
The process of designing the E-R diagram is The process of designing the E-R diagram is iterativeiterative
E-R Diagrams: Entity ClassesE-R Diagrams: Entity Classes
Entity classes are represented by rectanglesEntity classes are represented by rectangleswith the name insidewith the name inside
Attributes are represented by ovals. Attributes are represented by ovals.
– key attributes are underlinedkey attributes are underlined
– Multi-valued attributes are double-linedMulti-valued attributes are double-lined
– Derived attributes are dashedDerived attributes are dashed
Example of an entity class Example of an entity class
lastName accountIdfirstName
numberRentals
balance
otherUsers
AttributeKey
Attribute
DerivedAttribute
Multi-valued
Attribute
Customer
address
zipcode
statecity
street
CompositeAttribute
ComponentAttribute
EntityClass
ExampleExample
EntityClass
Attribute
KeyAttribute
Video
videotapeId title genre
length
dateAcquired
rating
E-R diagrams: RelationshipsE-R diagrams: Relationships
A relationship is represented by a A relationship is represented by a rhombus (diamond) with the name insiderhombus (diamond) with the name insideThe name of a relationship is a verb The name of a relationship is a verb describing itdescribing itAdditional symbols of a relationship:Additional symbols of a relationship:– CardinalityCardinality– Optional/mandatory participationOptional/mandatory participation– Attributes of a relationshipAttributes of a relationship
Example of a relationshipExample of a relationship
RelationshipType
EntityClass
RelationshipAttribute
Store VideoOwns
costpurchase
Date
EntityClass
IsOwnedBy
AlternateRelationship
Name
ExampleExample
to-manyrelationship
role
Store VideoOwns
costpurchase
DateTo-one
relationshiprole
OptionalparticipationConstraint
MandatoryparticipationConstraint
1 M
IsOwnedBy
Modeling relations as entity classesModeling relations as entity classes
1Customer
MVideoRents
dateRented
costdateDue
MCustomer
MVideoPreviously
Rented
dateRented
costdate
Returned
Modeling relations as entity classesModeling relations as entity classes
A relationship can be A relationship can be modeled as an entity modeled as an entity classclass
Video1
Customer1
Has Rental1
MHas
costdateDue dateRented
Modeling relations as entity classesModeling relations as entity classes
Note cardinalities and participation Note cardinalities and participation constraintsconstraints– A Rental entity cannot exist without being A Rental entity cannot exist without being
related to both a customer and a videorelated to both a customer and a video
Problem occurs because Rental has no Problem occurs because Rental has no key attributekey attribute
Weak and Strong entitiesWeak and Strong entities
A A weak entity classweak entity class is is – An entity class with no key of its ownAn entity class with no key of its own– An entity class whose entities cannot exist An entity class whose entities cannot exist
without being related to other entitieswithout being related to other entities
An An identifying relationshipidentifying relationship type is type is– A relationship type that determines the keys A relationship type that determines the keys
of the weak entitiesof the weak entities
Weak and Strong entitiesWeak and Strong entities
Video1
Customer1
Has Rental1
MHas
IdentifyingRelationship
Type
Weak EntityClass
costdateDue dateRented
Owner EntityClass
More on Weak Entities and More on Weak Entities and RelationsRelations
An entity that is An entity that is identified by its identified by its relationship to other relationship to other entities is called a entities is called a weakweak entity and its entity and its class a class a weak entity weak entity classclass
DEPENDENT
EMPLOYEE
Ssn Name
Name BdateRelation
DEPENDENTS_OF
111111
1
N
More on Weak Entities and More on Weak Entities and RelationsRelations
The stronger entity class is called the The stronger entity class is called the identifyingidentifying or or ownerowner entity class entity class
The relationship that relates the weak entity The relationship that relates the weak entity class to its owner is called: class to its owner is called: identifyingidentifying relationshiprelationship
AA partial key partial key of a weak entity is a set of of a weak entity is a set of attributes that uniquely identifies weak entities attributes that uniquely identifies weak entities related to the same owner entityrelated to the same owner entity
ExampleExample
Entities:Entities:Customer (key: account , last name, first Customer (key: account , last name, first name, address, email, credit card, name, address, email, credit card, password)password)
Movie (key: id, title, genre, length)Movie (key: id, title, genre, length)
Sale (key: id, cost, date, credit card)Sale (key: id, cost, date, credit card)Shopping Cart (key: id, date)Shopping Cart (key: id, date)
ExampleExample
Relationship Relationship TypeType
Entity ClassEntity Class Entity ClassEntity Class Cardinality Cardinality RatioRatio
AttibutesAttibutes
PurchasesPurchases CustomerCustomer SaleSale one-to-manyone-to-many
IncludesIncludes SaleSale MovieMovie many-to-many-to-manymany
quantityquantity
SelectsSelects CustomerCustomer ShoppingCartShoppingCart one-to-manyone-to-many
IncludesIncludes ShoppingCarShoppingCartt
MovieMovie many-to-many-to-manymany
quantityquantity