Database Systems (資料庫系統)

Slides:



Advertisements
Similar presentations
Constraints in Entity-Relationship Models Zaki Malik September 18, 2008.
Advertisements

The Entity-Relationship Model
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.
The Entity-Relationship Model
Comp3300/fall021 The Entity-Relationship Model Chapter 2 What are the steps in designing a database ? Why is the ER model used to create an initial design?
The Entity-Relationship Model
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 The Entity-Relationship Model Chapter 2.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 The Entity-Relationship Model Chapter 2.
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.
Modeling Your Data Chapter 2. Overview of Database Design Conceptual design: –What are the entities and relationships in the enterprise? – What information.
The Entity- Relationship Model CS 186 Fall 2002: Lecture 2 R &G - Chapter 2 A relationship, I think, is like a shark, you know? It has to constantly move.
The Entity-Relationship (ER) Model CS541 Computer Science Department Rutgers University.
1 Data Modeling Yanlei Diao UMass Amherst Feb 1, 2007 Slides Courtesy of R. Ramakrishnan and J. Gehrke.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 The Entity-Relationship Model Chapter 2.
ER continued, and ER to Relational Mappings R&G Chapters 2, 3 Lecture 22.
1 The Entity-Relationship Model Chapter 2. 2 Database Design Process  Requirement collection and analysis  DB requirements and functional requirements.
The Entity-Relationship Model. 421B: Database Systems - ER Model 2 Overview of Database Design q Conceptual Design -- A first model of the real world.
1 Database Systems ( 資料庫系統 ) September 24, 2014 Lecture #2.
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.
ER to Relational Mapping. Logical DB Design: ER to Relational Entity sets to tables. CREATE TABLE Employees (ssn CHAR (11), name CHAR (20), lot INTEGER,
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 The Entity-Relationship Model Chapter 2.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 The Entity-Relationship Model Chapter 2.
Chapter 2.  Conceptual design: (ER Model is used at this stage.) ◦ What are the entities and relationships in the enterprise? ◦ What information about.
CMPT 258 Database Systems The Entity-Relationship Model Part II (Chapter 2)
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.
1 Database Systems ( 資料庫系統 ) September 26, 2005 Lecture #2.
1 Database Systems ( 資料庫系統 ) September 27/28, 2006 Lecture #2.
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.
09/03/2009Lipyeow Lim -- University of Hawaii at Manoa 1 ICS 321 Fall 2009 Introduction to Database Design Asst. Prof. Lipyeow Lim Information & Computer.
The Entity-Relationship (ER) Model. Overview of db design Requirement analysis – Data to be stored – Applications to be built – Operations (most frequent)
CSC 411/511: DBMS Design 1 1 Dr. Nan WangCSC411_L2_ER Model 1 The Entity-Relationship Model (Chapter 2)
Mapping E/R to RM, R. Ramakrishnan and J. Gehrke with Dr. Eick’s additions 1 Mapping E/R Diagrams to Relational Database Schemas Second Half of Chapter.
1 Database Systems ( 資料庫系統 ) 9/23/2009 Lecture #2.
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.
A short review on entity- relationship modelling.
Database Management Systems, R. Ramakrishnan and J. Gehrke1 The Entity-Relationship Model Chapter 2.
COP Introduction to Database Structures
Introduction to Database Systems, CS420
The Entity-Relationship Model
Entity-Relationship Model
COP4710 Database Systems E-R Model.
MODELS OF DATABASE AND DATABASE DESIGN
ER-to-Relational Mapping
Constraints in Entity-Relationship Models
CPSC-310 Database Systems
The Entity-Relationship Model
The Entity-Relationship Model
Instructor: Elke Rundensteiner
From ER to Relational Model
The Entity-Relationship (ER) Model
The Entity-Relationship Model
The Entity-Relationship Model
The Entity-Relationship Model
The Entity-Relationship Model
Session 2 Welcome: The fifth learning sequence
The Entity-Relationship Model
The Entity-Relationship Model
CS4433 Database Systems E-R Model.
Question Which of the following plays an important role in representing information about the real world in a database? Explain briefly 1)DDL.
The Entity-Relationship Model
The Entity-Relationship Model
The Entity-Relationship Model
CS 405G: Introduction to Database Systems
The Entity-Relationship (ER) Model
Presentation transcript:

Database Systems (資料庫系統) 9/27 10/1, 2007 Lecture #2

Course Administration Office Hour: Thur 2-3 Can everyone get the textbook? HW #1 will be on the course homepage later today It is due 2 weeks from today. Next week reading: R&G Chapters 3 & 4.1~4.2

Chapter 2 Introduction to Database Design

Scenario Say if you are hired by iBeer Retailer as a computer consultant. iBeer wants you to design its database system. How to design it?

Database Design Step 1: Requirements Analysis What data to store in the database? What application (e.g., queries, updates, ..) needs from the database? Step 2: Conceptual Database Design Come up with the design: Entity-Relation (ER) model Sketch the design using pictures called entity-relationship diagrams. Step 3: Logical Database Design Implement the design: relational data model Easy to map ER diagrams into the relational data model (CH 3).

Requirement Analysis Requirement analysis: Conceptual database design The Beer retailer wants to keep track of Beers on shelves Beer manufacturers: [name & address] Conceptual database design ER diagram Logical database design: Relational model Beers Manfs ManfBy name addr Beer names Manufacturer's names 台灣啤酒 台灣菸酒公賣局 台灣生啤酒 青島啤酒 青島啤酒廠 Beer names 台灣啤酒 青島啤酒 台灣生啤酒 Manufacturer’s names Manufacturer’s addresses 台灣菸酒公賣局 台北市南昌路一段4號 青島啤酒廠 ??

ER Model: Entity (‘Joe’: string) (123: integer) (Joe, Alice, ..) name (123: integer) ssn Employees (Joe, Alice, ..) Proposed by Peter Chen (BS NTU EE ‘68) in 1976. Entity: A real-world object distinguishable from other objects (e.g., Joe). An entity is described by a set of attributes. Each attribute has a domain of possible values. Entity Set: a collection of similar entities Each entity in an entity set is uniquely identified by a key attribute.

ER Model: Relationship (5/2001) since name dname ssn did budget (Joe) Employees Works_In Departments (finance dept) Relationship: Association among two or more entities Joe works in finance department. A relationship can have descriptive attributes. Joe has worked in finance department since 5/2001. Relationship Set: Collection of similar relationships. 4

Ternary Relationship (Joe) (finance dept) (Taipei) since name dname ssn did budget Employees Works_In Departments (Joe) (finance dept) address capacity Locations (Taipei) 4

Roles in Relationship (Roles) name ssn Employees supervisor subordinate Reports_To

Key Constraints Describe at most once (entitity) relationship Manages relationship: each department has at most one manager (okay to have none). One department can appear at most once in Manages relationship set, also called one-to-many relation. dname name since ssn did budget Employees Manages Departments at most once = zero time? Finance Mary 3/3/93 Accounting Joe 2/2/92 Research Alice 3/1/92 Legal Peter 6

More Key Constraints Women Give Birth Babies 1-to-1 1-to Many IP address and hostnames Many-to-Many Marry Women Men Men Befriend Women 6

Participation Constraints Describe all (entitity) participation relationship Must every department have a manager? If yes, this is a participation constraint All Departments entities must participate in the Manages relationship set (total participation). since since name name dname dname ssn lot did did budget budget one and only one Employees Manages Departments Works_In since 8

Weak Entities A weak entity can be identified uniquely only by considering the key of another (owner) entity. Pname = partial key Owner entity set and weak entity set must participate in a one-to-many relationship set (one owner, many weak entities). Weak entity set must have total participation in this identifying relationship set. (Alicia) (2) name cost ssn pname age (Hao) Employees Policy Dependents 10

ISA (`is a’) Hierarchies name ssn Employees superclass entity hourly_wages hours_worked ISA contractid subclass entities Hourly_Emps Contract_Emps As in C++ and OO languages, attributes are inherited from superclass. A ISA B, every A entity is also considered to be a B entity. Why using ISA? Add descriptive attributes specific (make sense) to a subclass. Identify entities that make sense to a relationship (policy). 12

ISA (`is a’) Constraints name ssn Employees hourly_wages hours_worked ISA contractid Hourly_Emps Contract_Emps Overlap constraints: Can Joe be an Hourly_Emps as well as a Contract_Emps entity? (Allowed/disallowed) Covering constraints: Does every Employees entity also have to be an Hourly_Emps or a Contract_Emps entity? (Yes/no) 12

Aggregation Create relationship set from relationship sets. name ssn Create relationship set from relationship sets. Aggregation: relationship set turns into an entity set So that they can participate in (other) relationships. Employees Monitors until Can we add a relationship set between an relationship set and an entity started_on since dname pid pbudget did budget Projects Sponsors Departments 2

Design Guideline Avoid redundancy. Don’t use an entity set when an attribute will do. Limit the use of weak entity sets.

Avoiding Redundancy Redundancy occurs when we say the same thing in two different ways. Redundancy is bad wastes space encourages inconsistency. The two instances of the same fact may become inconsistent if we change one and forget to change the other instance.

Redundancy Example name name addr ManfBy Beers Manfs manf This design states the manufacturer of a beer twice: as an attribute and as a related entity.

Fix Redundancy name name addr ManfBy Beers Manfs This design gives the address of each manufacturer exactly once.

Example: Bad name manf manfAddr Beers This design repeats the manufacturer’s address once for each beer. Why is it bad? Manf updates its address. Loses the address if there are temporarily no beers for a manufacturer.

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.

Exercise 2.2 (R-G Book) A university database contains information about professors (identified by social security number) and courses (identified by courseid). Professors teach courses; each of the following situations concerns the Teaches relationship set. For each situation, draw an ER diagram that describes it. Professors can teach the same course in several semesters, and each offering must be recorded.

Professors can teach the same course in several semesters, and only the most recent such offering needs to be recorded. Every professor must teach some courses

Every professor teaches exactly one course (no more, no less) Every professor teaches exactly one course (no more, no less), and every course must be taught by some professor

Exercise 2.3 (R-G Book) Professors have an SSN, a name, an age, a rank, and a research specialty. Projects have a project number, a sponsor name (e.g., NSF), a starting date, an ending date, and a budget.

Graduate students have an SSN, a name, an age, and a degree program Each project is managed by exactly one professor (known as PI) Each project is worked in by one or more professors (known as Co-PIs) Each project is worked on by one or more graduate students (known as RAs)

When graduate students work on a project, a professor must supervise their work on the project. Graduate students can work on multiple projects, in which case they will have a potentially different supervisor for each project. Departments have a department number, a department name, and a main office. Department has a professor (known as Chairman) who runs the department.

Professors work in one or more departments, and for each department that they work in, a time percentage is associated with their job Graduate students have one major department in which they are working on their degree. Each graduate student must have another, more senior graduate student as an advisor.

Summary ER model is popular for conceptual design Sketch the design of a database informally using pictures Basic constructs in ER model: entities, relationships, and attributes (of entities and relationships). Some additional constructs: weak entities, ISA hierarchies, and aggregation. Several kinds of integrity constraints: key constraints, participation constraints, and overlap/covering constraints for ISA hierarchies. Design guideline in ER model 11

Ubicomp Project of the Week: Hyperdragging (SONY CSL, 1999) How to bring human computer interaction (desktop PC) into the physical environment (just a bit)? “Disappearing computing”

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

Example: Okay name name addr 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: Beers Entity not Needed name name addr ManfBy Beers Manfs Beers can be an attribute rather than an entity.

Example: Okay 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.