Introduction to Database Systems, CS420

Slides:



Advertisements
Similar presentations
Conceptual Design using the Entity-Relationship Model
Advertisements

Constraints in Entity-Relationship Models Zaki Malik September 18, 2008.
Database Management Systems Chapter 3 The Relational Data Model (I) Instructor: Li Ma Department of Computer Science Texas Southern University, Houston.
Database Management Systems, R. Ramakrishnan and J. Gehrke1 The Entity-Relationship Model Chapter 2.
CSCI 305 – Fall 2013 The Entity-Relationship Model Based on Slides by Prof. Brian King.
Database Management Systems, R. Ramakrishnan and J. Gehrke1 The Entity-Relationship Model Chapter 2.
1 541: Database Systems S. Muthu Muthukrishnan. 2 Overview of Database Design  Conceptual design: (ER Model is used at this stage.)  What are the entities.
The Entity-Relationship (ER) Model
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 The Entity-Relationship Model Chapter 2.
1 Convert E/R to Relation May 18, Entity Set -> Relation Relation: Beers(name, manf) Beers name manf.
Databases : Relational Model 2007, Fall Pusan National University Ki-Joune Li These slides are made from the materials that Prof. Jeffrey D. Ullman distributes.
Chapter 4 Notes. Entity-Relationship Model E/R Diagrams Weak Entity Sets Converting E/R Diagrams to Relations.
CS34311 The Entity- Relationship Model Part 4.. CS34312 Coming up with a good design for your application Guidelines via examples.
1 Relational Model and Translating ER into Relational.
The Relational Data Model Database Model (E/R) Relational Schema Physical storage Diagrams (E/R) Tables: row names: attributes rows: tuples Complex file.
1 Announcement Recitation time  Before midterm: 6-7pm, by Earl Wagner  After midterm: 5-6pm, by Yi Qiao Newsgroup safe to subscribe  Will not cause.
The Entity-Relationship (ER) Model CS541 Computer Science Department Rutgers University.
1 The Relational Data Model Tables Schemas Conversion from E/R to Relations.
From E/R Diagrams to Relations. The Relational Data Model Database Model (E/R) Relational Schema Physical storage Diagrams (E/R) Tables: row names: attributes.
Fall 2001Arthur Keller – CS 1803–1 Schedule Today Oct. 2 (T) Relational Model. u Read Sections Assignment 1 due. Personal Letter of Introduction.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 The Entity-Relationship Model Chapter 2.
1 The Relational Data Model Tables Schemas Conversion from E/R to Relations Source: slides by Jeffrey Ullman.
Modeling Your Data Chapter 2. Part II Discussion of the Model: Good Design/ Bad Design?
CS411 Database Systems Kazuhiro Minami
1 The Entity-Relationship Model Chapter 2. 2 Overview of Database Design  Conceptual design : (ER Model is used at this stage.)  What are the entities.
1 The Relational Data Model Tables Schemas Conversion from E/R to Relations.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 The Entity-Relationship Model Chapter 2.
CMPT 258 Database Systems The Entity-Relationship Model Part II (Chapter 2)
1 Entity-Relationship Model E/R Diagrams Weak Entity Sets Converting E/R Diagrams to Relations.
Dale Roberts 1 Department of Computer and Information Science, School of Science, IUPUI Dale Roberts, Lecturer Computer Science, IUPUI
ER Data Models Ctd. CSET 3300.
Christoph F. Eick: Designing E/R Diagrams 1 The Entity-Relationship Model Chapter 3+4.
LECTURE 1: Entity Relationship MODEL. Think before doing it! Like most of the software projects, you need to think before you do something. Before developing.
Tallahassee, Florida, 2015 COP4710 Database Systems E-R Model Fall 2015.
Data Modeling Translating E-R Diagrams to Relations
09/03/2009Lipyeow Lim -- University of Hawaii at Manoa 1 ICS 321 Fall 2009 Introduction to Database Design Asst. Prof. Lipyeow Lim Information & Computer.
1 Conceptual Design using the Entity- Relationship Model.
CS 405G: Introduction to Database Systems Lecture 5: Logical Design by Relational Model Instructor: Chen Qian.
Databases 1 Fifth lecture. Entity-Relationship Model Diagrams Class hierarchies Weak entity sets From E/R diagrams to Relations 2.
Instructor: Jinze Liu Fall Phases of Database Design u Conceptual design begins with the collection of requirements and results needed from the.
Entity-Relationship Model E/R Diagrams Converting E/R Diagrams to Relations.
CS 405G: Introduction to Database Systems Relations.
Modeling Your Data Chapter 2 cs5421. Part II Discussion of the Model: Good Design/ Bad Design? cs5422.
LECTURE 1: Entity Relationship MODEL. Think before doing it! Like most of the software projects, you need to think before you do something. Before developing.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 The Entity-Relationship Model Chapter 2.
1 The Relational Data Model Tables Schemas Conversion from E/R to Relations.
CS422 Principles of Database Systems From ER to Relations Chengyu Sun California State University, Los Angeles Adapted from Jeffrey Ullman’s lecture notes.
Database Management Systems, R. Ramakrishnan and J. Gehrke1 The Entity-Relationship Model Chapter 2.
COP Introduction to Database Structures
Entity-Relationship Model
COP4710 Database Systems E-R Model.
Cushing, Keller, UlmanJudy Cushing
Constraints in Entity-Relationship Models
CPSC-310 Database Systems
The Entity-Relationship Model
Modeling Your Data Chapter 2 cs542
Instructor: Zhe He Department of Computer Science
Database Systems (資料庫系統)
CPSC-310 Database Systems
The Entity-Relationship Model
The Entity-Relationship Model
Session 2 Welcome: The fifth learning sequence
The Relational Data Model
CS4433 Database Systems E-R Model.
CS 405G Introduction to Database Systems
CS 505: Intermediate Topics to Database Systems
The Entity-Relationship Model
CS 405G: Introduction to Database Systems
The Entity-Relationship (ER) Model
CS 405G: Introduction to Database Systems
Presentation transcript:

Introduction to Database Systems, CS420 Relational Database Design

Agenda Entity Sets Versus Attributes Weak Entity Sets Design Choices Case Study From E/R Diagrams to Relations

Entity Sets Versus Attributes An entity set should satisfy at least one of the following conditions: It is more than the name of something; it has at least one non-key attribute. or It is the “many” in a many-one or many-many relationship.

Example: Good name name addr Beers Manfs ManfBy Beers Manfs Manfs deserves to be an entity set because of the nonkey attribute addr. Beers deserves to be an entity set because it is the “many” of the many-one relationship ManfBy.

Example: Good name manf Beers There is no need to make the manufacturer an entity set, because we record nothing about manufacturers besides their name.

Example: Bad name name ManfBy Beers Manfs Since the manufacturer is nothing but a name, and is not at the “many” end of any relationship, it should not be an entity set.

Weak Entity Sets

Don’t Overuse Weak Entity Sets Beginning database designers often doubt that anything could be a key by itself. They make all entity sets weak, supported by all other entity sets to which they are linked. In reality, we usually create unique ID’s for entity sets. Examples include social-security numbers, automobile VIN’s etc.

When Do We Need Weak Entity Sets? The usual reason is that there is no global authority capable of creating unique ID’s. Example: it is unlikely that there could be an agreement to assign unique player numbers across all football teams in the world.

ER Design What are the entities and relationships in the enterprise? What information about these entities and relationships should we store in the database? What are the integrity constraints or business rules that hold?

Design Choices

Design Choices Should a concept be modeled as an entity or an attribute? Should a concept be modeled as an entity or a relationship? What constraints should be captured?

Entity vs. Attribute Should address be an attribute of Employees or an entity (connected to Employees by a relationship)? Address address … ? Employees Employees

Entity vs. Attribute Depend upon the use we want to make of address information, and the semantics of the data If we have several addresses per employee, address must be an entity (since attributes cannot be set-valued) At Employees Address

Entity vs. Attribute If the structure (city, street, etc) is important, e.g., we want to retrieve employees in a given city, address must be modeled an entity (since attribute values are atomic) city At Address Employees Street zip

Entity vs. Attribute Emp Dept What Problem? dname name from to ssn lot did budget Works_In Emp Dept What Problem? Works_In does not allow an employee to work in a department for two or more periods

Entity vs. Attribute Emp Dept Duration dname name ssn lot did budget Works_In2 Emp Dept from to Duration Works_In2 now allows an employee to work in a department for two or more periods

Entity vs. Relationship dname name since dbudget ssn lot did budget Manages Emp Dept OK if a manager gets a budget for each dept What if a manager gets a budget that covers all managed depts?

Entity vs. Relationship name ssn lot dname Emp since dbudget did budget Manages Managers Dept New entity set Managers (isa Emp) dbudget describes a manager, as intended

Case Study

ER Design Case Study Books Customers cname title odate qty isbn price cid address Orders Books Customers What if a customer places two orders for the same book in one day? The second order is handled by updating the value of quantity

ER Design Case Study Books Customers cname title odate qty isbn price cid address Orders Books Customers What if a customer places two orders for two different books in one day? No problem. Each order relates the customer to a different book.

ER Design Case Study Books Customers cname title Order_ date qty isbn price cid address Orders Books Customers What if a customer places two orders for the same book on different days? Can we use the order date to distinguish the two orders? No we can’t. The attributes of Books and Customers must jointly contain a key for Orders. Thus this design does not allow a customer to place orders for the same book on different days.

From E-R Diagram to Relations

From E/R Diagrams to Relations Entity set -> relation. Attributes -> attributes. Relationships -> relations whose attributes are only: The keys of the connected entity sets. Attributes of the relationship itself.

Entity Set  Relation Relation: Beers(name, manf) name manf Beers

Relationship  Relation name name addr manf Drinkers Likes Likes(drinker, beer) Beers Married husband wife Married(husband, wife) Buddies 1 2 Buddies(name1, name2) Favorite Favorite(drinker, beer)

Combining Relations OK to combine into one relation: The relation for an entity-set E The relations for many-one relationships of which E is the “many.” Example: Drinkers(name, addr) and Favorite(drinker, beer) combine to make Drinker1(name, addr, favBeer).

Example: Weak Entity Set  Relation name name Logins At Hosts location billTo Hosts(hostName, location) Logins(loginName, hostName, billTo) At(loginName, hostName, hostName2) At becomes part of Logins Must be the same

Subclasses: Three Approaches Object-oriented : One relation per subset of subclasses, with all relevant attributes. Use nulls : One relation; entities have NULL in attributes that don’t belong to them. E/R style : One relation for each subclass: Key attribute(s). Attributes of that subclass.

Example: Subclass Beers name manf isa Ales color

Object-Oriented name manf Bud Anheuser-Busch Beers name manf color Summerbrew Pete’s dark Ales Good for queries like “find the color of Ales made by Pete’s.”

E/R Style name manf Bud Anheuser-Busch Summerbrew Pete’s Beers name color Summerbrew dark Ales Good for queries like “find all Beers (including ales) made by Pete’s.”

Using Nulls name manf color Bud Anheuser-Busch NULL Summerbrew Pete’s dark Beers Saves space unless there are lots of attributes that are usually NULL.

Summary ER design is subjective. There are often many ways to model a given scenario. Entity vs. attribute Entity vs. relationship From E/R Diagrams to Relations

END