25
Conceptual Database Design

Conceptual Database Design. Building an Application with a DBMS Requirements modeling (conceptual, pictures) –Decide what entities should be part of the

Embed Size (px)

Citation preview

Page 1: Conceptual Database Design. Building an Application with a DBMS Requirements modeling (conceptual, pictures) –Decide what entities should be part of the

Conceptual Database Design

Page 2: Conceptual Database Design. Building an Application with a DBMS Requirements modeling (conceptual, pictures) –Decide what entities should be part of the

Building an Application with a DBMS

• Requirements modeling (conceptual, pictures)– 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.

– Define the tables in the database system.

– Populate database (insert tuples).

• Write application programs using the DBMS– way easier now that the data management is taken care of.

Page 3: Conceptual Database Design. Building an Application with a DBMS Requirements modeling (conceptual, pictures) –Decide what entities should be part of the

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: Conceptual Database Design. Building an Application with a DBMS Requirements modeling (conceptual, pictures) –Decide what entities should be part of the

Database Design Formalisms1. Object Definition Language (ODL):

– Closer in spirit to object-oriented models

– I don’t teach it anymore.

2. Entity/Relationship model (E/R):– More relational in nature.

• Both can be translated (semi-automatically) to relational schemas

• ODL to OO-schema: direct transformation (C++ or Smalltalk based system).

Page 5: Conceptual Database Design. Building an Application with a DBMS Requirements modeling (conceptual, pictures) –Decide what entities should be part of the

2. Entity / Relationship Diagrams

Entities

Attributes

Relationships between entities

Product

address

buys

Page 6: Conceptual Database Design. Building an Application with a DBMS Requirements modeling (conceptual, pictures) –Decide what entities should be part of the

Keys in E/R Diagrams

• Every entity set must have a key

Product

name category

price

Page 7: Conceptual Database Design. Building an Application with a DBMS Requirements modeling (conceptual, pictures) –Decide what entities should be part of the

address name ssn

Person

buys

makes

employs

CompanyProduct

name category

stockprice

name

price

Page 8: Conceptual Database Design. Building an Application with a DBMS Requirements modeling (conceptual, pictures) –Decide what entities should be part of the

What is a Relation ?

• A mathematical definition:– if A, B are sets, then a relation R is a subset of

A x B

• A={1,2,3}, B={a,b,c,d}, R = {(1,a), (1,c), (3,b)}

- makes is a subset of Product x Company:

1

2

3

a

b

c

d

A=

B=

makes CompanyProduct

Page 9: Conceptual Database Design. Building an Application with a DBMS Requirements modeling (conceptual, pictures) –Decide what entities should be part of the

Multiplicity of E/R Relations

• one-one:

• many-one

• many-many

123

abcd

123

abcd

123

abcd

Page 10: Conceptual Database Design. Building an Application with a DBMS Requirements modeling (conceptual, pictures) –Decide what entities should be part of the

address name ssn

Person

buys

makes

employs

CompanyProduct

name category

stockprice

name

price

What doesthis say ?

Page 11: Conceptual Database Design. Building an Application with a DBMS Requirements modeling (conceptual, pictures) –Decide what entities should be part of the

Multi-way RelationshipsHow do we model a purchase relationship between buyers,products and stores?

Purchase

Product

Person

Store

Can still model as a mathematical set (how ?)

Page 12: Conceptual Database Design. Building an Application with a DBMS Requirements modeling (conceptual, pictures) –Decide what entities should be part of the

Q: what does the arrow mean ?

A: if I know the store, person, invoice, I know the movie too

Rental

VideoStore

Person

Movie

Invoice

Arrows in Multiway Relationships

Page 13: Conceptual Database Design. Building an Application with a DBMS Requirements modeling (conceptual, pictures) –Decide what entities should be part of the

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: Conceptual Database Design. Building an Application with a DBMS Requirements modeling (conceptual, pictures) –Decide what entities should be part of the

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: Conceptual Database Design. Building an Application with a DBMS Requirements modeling (conceptual, pictures) –Decide what entities should be part of the

Roles in Relationships

Purchase

What if we need an entity set twice in one relationship?

Product

Person

Store

salesperson buyer

Page 16: Conceptual Database Design. Building an Application with a DBMS Requirements modeling (conceptual, pictures) –Decide what entities should be part of the

Attributes on Relationships

Purchase

Product

Person

Store

date

Page 17: Conceptual Database Design. Building an Application with a DBMS Requirements modeling (conceptual, pictures) –Decide what entities should be part of the

Converting Multi-way Relationships to Binary

Purchase

Person

Store

Product

StoreOf

ProductOf

BuyerOf

date

Page 18: Conceptual Database Design. Building an Application with a DBMS Requirements modeling (conceptual, pictures) –Decide what entities should be part of the

From E/R Diagramsto Relational Schema

• Entity set relation

• Relationship relation

Page 19: Conceptual Database Design. Building an Application with a DBMS Requirements modeling (conceptual, pictures) –Decide what entities should be part of the

Entity Set to Relation

Product

name category

price

Product(name, category, price)

name category price

gizmo gadgets $19.99

Page 20: Conceptual Database Design. Building an Application with a DBMS Requirements modeling (conceptual, pictures) –Decide what entities should be part of the

Relationships to Relations

makes CompanyProduct

name category

Stock price

name

Makes(product-name, product-category, company-name, year) Product-name Product-Category Company-name Starting-year

gizmo gadgets gizmoWorks 1963

Start Year

price

(watch out for attribute name conflicts)

Page 21: Conceptual Database Design. Building an Application with a DBMS Requirements modeling (conceptual, pictures) –Decide what entities should be part of the

Relationships to Relations

makes CompanyProduct

name category

Stock price

name

No need for Makes. Modify Product:

name category price StartYear companyName

gizmo gadgets 19.99 1963 gizmoWorks

Start Year

price

Page 22: Conceptual Database Design. Building an Application with a DBMS Requirements modeling (conceptual, pictures) –Decide what entities should be part of the

Multi-way Relationships to Relations

Purchase

Product

Person

Storename price

ssn name

name address

Purchase( , , )

Page 23: Conceptual Database Design. Building an Application with a DBMS Requirements modeling (conceptual, pictures) –Decide what entities should be part of the

3. Design Principles

PurchaseProduct Person

What’s wrong?

President PersonCountry

Page 24: Conceptual Database Design. Building an Application with a DBMS Requirements modeling (conceptual, pictures) –Decide what entities should be part of the

Design Principles:What’s Wrong?

Purchase

Product

Store

date

personNamepersonAddr

Moral: pick the right kind of entities.

Page 25: Conceptual Database Design. Building an Application with a DBMS Requirements modeling (conceptual, pictures) –Decide what entities should be part of the

Design Principles:What’s Wrong?

Purchase

Product

Person

Store

dateDates

Moral: don’t complicate life more than it already is.