lecture 07: conceptual database design
DESCRIPTION
Lecture 07: Conceptual Database Design. Building an Application with a DBMS. Requirements modeling (conceptual) Decide what entities should be part of the application and how they should be linked. Schema design and implementation Decide on a set of tables, attributes. - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: Lecture 07: Conceptual Database Design](https://reader034.vdocuments.net/reader034/viewer/2022051316/56815787550346895dc51bc4/html5/thumbnails/1.jpg)
Lecture 07: Conceptual Database Design
![Page 2: Lecture 07: Conceptual Database Design](https://reader034.vdocuments.net/reader034/viewer/2022051316/56815787550346895dc51bc4/html5/thumbnails/2.jpg)
Building an Application with a DBMS
1. Requirements modeling (conceptual)– Decide what entities should be part of the application and
how they should be linked.
2. Schema design and implementation– Decide on a set of tables, attributes.– Define the tables in the database system.– Populate database (insert tuples).
3. Write application programs using the DBMS– Way easier now that the data management is taken care of.
![Page 3: Lecture 07: Conceptual Database Design](https://reader034.vdocuments.net/reader034/viewer/2022051316/56815787550346895dc51bc4/html5/thumbnails/3.jpg)
Database Design
• Why do we need it?– Agree on structure of the database before
deciding on a particular implementation.• Consider issues such as:
– What entities to model– How entities are related– What constraints exist in the domain– How to achieve good designs
![Page 4: Lecture 07: Conceptual Database Design](https://reader034.vdocuments.net/reader034/viewer/2022051316/56815787550346895dc51bc4/html5/thumbnails/4.jpg)
Database Design Formalisms1. Object Definition Language (ODL):
– Closer in spirit to object-oriented models– Not in the scope of this course
2. Entity/Relationship model (E/R):– More relational in nature.– Related to the EER modeling in the MySQL workbench
but we use different conventions here!
• Both can be translated to relational schemas
![Page 5: Lecture 07: Conceptual Database Design](https://reader034.vdocuments.net/reader034/viewer/2022051316/56815787550346895dc51bc4/html5/thumbnails/5.jpg)
Entity / Relationship Diagrams
Entity sets
Attributes
Relationships between entities
Product
address
buys
![Page 6: Lecture 07: Conceptual Database Design](https://reader034.vdocuments.net/reader034/viewer/2022051316/56815787550346895dc51bc4/html5/thumbnails/6.jpg)
Keys in E/R Diagrams
• Every entity set must have a key
Product
name category
price
![Page 7: Lecture 07: Conceptual Database Design](https://reader034.vdocuments.net/reader034/viewer/2022051316/56815787550346895dc51bc4/html5/thumbnails/7.jpg)
buys
makes
employs
Company
name category stockprice name
price
address name ssn
Person
Product
![Page 8: Lecture 07: Conceptual Database Design](https://reader034.vdocuments.net/reader034/viewer/2022051316/56815787550346895dc51bc4/html5/thumbnails/8.jpg)
What is a Relation ?
• A mathematical definition:– if A, B are sets, then a relation R is a subset of
A B• A={1,2,3}, B={a,b,c,d},
R = {1,a, 1,c, 3,b}
- makes is a subset of Product Company:
1
2
3
a
b
c
d
A= =B
makes CompanyProduct
![Page 9: Lecture 07: Conceptual Database Design](https://reader034.vdocuments.net/reader034/viewer/2022051316/56815787550346895dc51bc4/html5/thumbnails/9.jpg)
Multiplicity of E/R Relations
• one-one:
• many-one
• many-many
123
abcd
123
abcd
123
abcd
![Page 10: Lecture 07: Conceptual Database Design](https://reader034.vdocuments.net/reader034/viewer/2022051316/56815787550346895dc51bc4/html5/thumbnails/10.jpg)
buys
makes
employs
Company
name category stockprice name
price
address name ssn
Person
Product
What doesit mean?
![Page 11: Lecture 07: Conceptual Database Design](https://reader034.vdocuments.net/reader034/viewer/2022051316/56815787550346895dc51bc4/html5/thumbnails/11.jpg)
Multi-way RelationshipsHow do we model a purchase relationship between buyers,products and stores?
Purchase
Product
Person
Can still model as a mathematical set (how?)
Store
![Page 12: Lecture 07: Conceptual Database Design](https://reader034.vdocuments.net/reader034/viewer/2022051316/56815787550346895dc51bc4/html5/thumbnails/12.jpg)
Q: what does the arrow mean ?
A: if I know the movie, role and actor, I know the salary too
Plays
Movie
Actor
Salary
Role
Arrows in Multiway Relationships
![Page 13: Lecture 07: Conceptual Database Design](https://reader034.vdocuments.net/reader034/viewer/2022051316/56815787550346895dc51bc4/html5/thumbnails/13.jpg)
Q: what do these arrow mean ?
A: store, person, invoice determines movie and store, invoice, movie determines person
Rental
VideoStore
Person
Movie
Invoice
Arrows in Multiway Relationships
![Page 14: Lecture 07: Conceptual Database Design](https://reader034.vdocuments.net/reader034/viewer/2022051316/56815787550346895dc51bc4/html5/thumbnails/14.jpg)
Q: how do I say: “invoice determines store” ?
A: no good way; best approximation:
Q: Why is this incomplete ?
Rental
VideoStore
Person
Movie
Invoice
Arrows in Multiway Relationships
![Page 15: Lecture 07: Conceptual Database Design](https://reader034.vdocuments.net/reader034/viewer/2022051316/56815787550346895dc51bc4/html5/thumbnails/15.jpg)
Roles in Relationships
Purchase
What if we need an entity set twice in one relationship?
Product
Person
Store
seller buyer
![Page 16: Lecture 07: Conceptual Database Design](https://reader034.vdocuments.net/reader034/viewer/2022051316/56815787550346895dc51bc4/html5/thumbnails/16.jpg)
Attributes on Relationships
Purchase
Product
Person
Store
date
![Page 17: Lecture 07: Conceptual Database Design](https://reader034.vdocuments.net/reader034/viewer/2022051316/56815787550346895dc51bc4/html5/thumbnails/17.jpg)
Converting Multi-way Relationships to Binary
Purchase
Person
Store
Product
StoreOf
ProductOf
BuyerOf
date
![Page 18: Lecture 07: Conceptual Database Design](https://reader034.vdocuments.net/reader034/viewer/2022051316/56815787550346895dc51bc4/html5/thumbnails/18.jpg)
From E/R Diagramsto Relational Schema
• Entity relation• Relationship relation
![Page 19: Lecture 07: Conceptual Database Design](https://reader034.vdocuments.net/reader034/viewer/2022051316/56815787550346895dc51bc4/html5/thumbnails/19.jpg)
Entity Set to Relation
Product
name category
price
Product(name, category, price)
name category price
gizmo gadgets $19.99
![Page 20: Lecture 07: Conceptual Database Design](https://reader034.vdocuments.net/reader034/viewer/2022051316/56815787550346895dc51bc4/html5/thumbnails/20.jpg)
Relationships to Relations
Makes(product-name, product-category, company-name, year) Product-name Product-Category Company-name Starting-year
gizmo gadgets gizmoWorks 1963
(watch out for attribute name conflicts)
makes CompanyProduct
name category
Stock price
nameStart Year
price
![Page 21: Lecture 07: Conceptual Database Design](https://reader034.vdocuments.net/reader034/viewer/2022051316/56815787550346895dc51bc4/html5/thumbnails/21.jpg)
Relationships to Relations
No need for Makes. Modify Product:
name category price StartYear companyName
gizmo gadgets 19.99 1963 gizmoWorks
makes CompanyProduct
name category
Stock price
nameStart Year
price
![Page 22: Lecture 07: Conceptual Database Design](https://reader034.vdocuments.net/reader034/viewer/2022051316/56815787550346895dc51bc4/html5/thumbnails/22.jpg)
Multi-way Relationships to Relations
Purchase
Product
Person
Storename price
ssn name
name address
Purchase( , , )
![Page 23: Lecture 07: Conceptual Database Design](https://reader034.vdocuments.net/reader034/viewer/2022051316/56815787550346895dc51bc4/html5/thumbnails/23.jpg)
3. Design Principles
PurchaseProduct Person
What’s wrong?
President PersonCountry
![Page 24: Lecture 07: Conceptual Database Design](https://reader034.vdocuments.net/reader034/viewer/2022051316/56815787550346895dc51bc4/html5/thumbnails/24.jpg)
Design Principles:What’s Wrong?
Purchase
Product
Store
date
personNamepersonAddr
Moral: pick the right kind of entities.
![Page 25: Lecture 07: Conceptual Database Design](https://reader034.vdocuments.net/reader034/viewer/2022051316/56815787550346895dc51bc4/html5/thumbnails/25.jpg)
Design Principles:What’s Wrong?
Purchase
Product
Person
Store
dateDates
Moral: don’t complicate life more than it already is.