ER Diagrams and Relational Model CS 174a (Winter 2015)

Slides:



Advertisements
Similar presentations
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,
Advertisements

Logical DB Design: ER to Relational Entity sets to tables. Employees ssn name lot CREATE TABLE Employees (ssn CHAR (11), name CHAR (20), lot INTEGER, PRIMARY.
Relational Database. Relational database: a set of relations Relation: made up of 2 parts: − Schema : specifies the name of relations, plus name and type.
Database Management Systems, R. Ramakrishnan and J. Gehrke1 The Entity-Relationship Model Chapter 2.
The Entity-Relationship (ER) Model
SQL Lecture 10 Inst: Haya Sammaneh. Example Instance of Students Relation  Cardinality = 3, degree = 5, all rows distinct.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke. Edited by Keith Shomper, The Relational Model Chapter 3.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 The Entity-Relationship Model Chapter 2.
1 Translation of ER-diagram into Relational Schema Prof. Sin-Min Lee Department of Computer Science.
SPRING 2004CENG 3521 The Relational Model Chapter 3.
The Relational Model 198:541 Rutgers University. Why Study the Relational Model?  Most widely used model. Vendors: IBM, Informix, Microsoft, Oracle,
1 Relational Model. 2 Relational Database: Definitions  Relational database: a set of relations  Relation: made up of 2 parts: – Instance : a table,
1 Data Modeling Yanlei Diao UMass Amherst Feb 1, 2007 Slides Courtesy of R. Ramakrishnan and J. Gehrke.
Sunday, June 28, Entity-Relationship and Enhanced Entity-Relationship Conceptual Data Models (Chapters 6 & Section 7.1)
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.
The Entity-Relationship Model. 421B: Database Systems - ER Model 2 Overview of Database Design q Conceptual Design -- A first model of the real world.
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,
1 The Relational Model Chapter 3. 2 Objectives  Representing data using the relational model.  Expressing integrity constraints on data.  Creating,
1 The Relational Model Chapter 3. 2 Why Study the Relational Model?  Most widely used model.  Vendors: IBM, Informix, Microsoft, Oracle, Sybase, etc.
1 The Relational Model Chapter 3. 2 Why Study the Relational Model?  Most widely used model  Vendors: IBM, Informix, Microsoft, Oracle, Sybase  Recent.
 Relational database: a set of relations.  Relation: made up of 2 parts: › Instance : a table, with rows and columns. #rows = cardinality, #fields =
1 Translation of ER-diagram into Relational Schema Prof. Sin-Min Lee Department of Computer Science.
1 The Relational Model Chapter 3. 2 Why Study the Relational Model?  Most widely used model.  Vendors: IBM, Informix, Microsoft, Oracle, Sybase, etc.
1 The Relational Model Chapter 3. 2 Why Study the Relational Model?  Most widely used model.  Vendors: IBM, Informix, Microsoft, Oracle, Sybase, etc.
1 The Relational Model. 2 Why Study the Relational Model? v Most widely used model. – Vendors: IBM, Informix, Microsoft, Oracle, Sybase, etc. v “Legacy.
FALL 2004CENG 351 File Structures and Data Management1 Relational Model Chapter 3.
1.1 CAS CS 460/660 Relational Model. 1.2 Review E/R Model: Entities, relationships, attributes Cardinalities: 1:1, 1:n, m:1, m:n Keys: superkeys, candidate.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 The Relational Model Chapter 3.
© D. Wong Ch. 2 Entity-Relationship Data Model (continue)  Data models  Entity-Relationship diagrams  Design Principles  Modeling of constraints.
Entity Relationship Diagram (2)
09/03/2009Lipyeow Lim -- University of Hawaii at Manoa 1 ICS 321 Fall 2009 Introduction to Database Design Asst. Prof. Lipyeow Lim Information & Computer.
Database Management Systems, R. Ramakrishnan and J. Gehrke1 The Relational Model Chapter 3.
CMPT 258 Database Systems The Relationship Model PartII (Chapter 3)
Lecture 3 Book Chapter 3 (part 2 ) From ER to Relational.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 The Relational Model Chapter 3.
The Entity-Relationship (ER) Model. Overview of db design Requirement analysis – Data to be stored – Applications to be built – Operations (most frequent)
The Entity-Relationship Model CIS 4301 Lecture Notes 1/12/2006.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 The Relational Model Chapter 3.
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.
©Silberschatz, Korth and Sudarshan2.1Database System Concepts Chapter 2: Entity-Relationship Model Entity Sets Relationship Sets Mapping Constraints Keys.
1 CS122A: Introduction to Data Management Lecture #4 (E-R  Relational Translation) Instructor: Chen Li.
CENG 351 File Structures and Data Management1 Relational Model Chapter 3.
Database Management Systems, R. Ramakrishnan and J. Gehrke1 The Entity-Relationship Model Chapter 2.
Chapter 2: Entity-Relationship Model
COP Introduction to Database Structures
CAS CS 460/660 Data Base Design Entity/Relationship Model
COP Introduction to Database Structures
Entity-Relationship Model
Chapter 2: Entity-Relationship Model
These slides are based on the slides of your text book.
The Relational Model Lecture 3 INFS614, Fall
Translation of ER-diagram into Relational Schema
From ER to Relational Model
The Entity-Relationship (ER) Model
Data Modelling Introduction
The Relational Model Chapter 3
The Relational Model Chapter 3
Translation of ER-diagram into Relational Schema
The Entity-Relationship Model
Chapter 6: Entity-Relationship Model
More on ER Model and the Relationship Model
The Relational Model Chapter 3
The Entity-Relationship Model
Chapter 2: Entity-Relationship Model
CS4222 Principles of Database System
The Entity-Relationship (ER) Model
Presentation transcript:

ER Diagrams and Relational Model CS 174a (Winter 2015)

ER Model Notations ICS 122 A Fall 2006

ER Model Notations

Class Hierarchies (ISA Relationship)  Lots of times an entity set has members that have special properties not associated with all the members of the entity set.  E.g., the set of checking accounts and savings accounts are a subset of the set of accounts. Checking has a overdraft amount, and savings has a interest-rate.  depending upon its type, savings and checking accounts may participate in different relationships.

Class Hierarchies - Example savings and checking are subclasses of the account entity set account is a superclass of savings and checking entity sets An entity in a subclass has to belong to superclass as well -- that is, every savingsaccount is also an account. Similarly every checking account is also an account Attribute Inheritance: subclasses inherit all the attributes of the superclass. Similarly, subclasses inherit all relationships in which the superclass participates account ISA savings checking account# balance interest rates overdraft amount

Class Hierarchies - Constraints Overlap Constraints Whether two subclasses are allowed to contain the same entity In previous example, if an account can be both Checking and Savings => Overlapping Constraint (Denoted by: Savings OVERLAPS Checking ) Else (Checking acct can never be Savings acct) => No Overlapping Constraint (Default) Covering Constraints Whether the entities in the subclasses collectively include all the entities of superclass Ex. If all the accounts are either checking or savings => Covering Constraint (denoted by: Checking AND Savings COVER Account) Else (there can be an acct which is neither Checking nor Savings) => No Covering constraint (Default)

Aggregation - Example Used when we have to model a relationship involving (entity sets and) a relationship set. Aggregation allows us to treat a relationship set as an entity set for purposes of participation in (other) relationships. Consider a relationship works-on between Employee and Project. Suppose we want to record managers for tasks performed by an employee in a project. We need to express relationship among works-on and manages relationships. In such cases, we use aggregation shown by dashed box around works-on (and its entities).

Solution using aggregation:

Aggregation vs Ternary Relationship Can we make it a ternary relationship? - works-on and manages have distinct attributes - also, cannot express constraints like ‘Employee on a project is managed by at most one manager’ If we do not have above constraint and no attributes for works-on, we may use ternary relationship.

Binary vs. Ternary Relationships If each policy is owned by just one employee: Key constraint on Policies would mean policy can only cover 1 dependent! (Arrow from Policies to Covers) Use two binary relationships to incorporate the constraint Bad design Better design age pname Covers Policies cost policyid Dependents Employees lot name ssn Dependents Beneficiary Purchaser Employees lot name ssn Policies cost policyid age pname

Binary vs Ternary Relationships When to use ternary relationship? Example: There are generic parts in the world, such as bolts or AA batteries. There are suppliers, such as Eveready. There are projects that need parts like bolts and batteries. A project leader may buys a particular quantity of a product from a particular supplier for given price. What if we use three binary relationships instead?

If we use binary instead of ternary: - “ProjectOwner buys from Eveready, Eveready supplies batteries, Project needs batteries” DOES NOT IMPLY “ProjectOwner buys batteries from Eveready”! - Also can not store quantity, price etc. In this case, it is better to use ternary relationship.

Homework Example:

Solution: Alternate solutions?

Relational Model - Basics

Relational Database: Definitions Relation : made up of 2 parts: Instance : a table, with rows and columns #rows = cardinality, #columns = arity / degree Schema : specifies name of relation, plus name and type of each column E.g. Students ( sid : string, name : string, login : string, age : integer, gpa : real) Can think of a relation as a set of rows or tuples (i.e., all rows are distinct) Relational database : a set of relations

Example:

Key Constraints Superkey: a set of attributes for which no two tuples have the same value - Every relation has at least one default superkey – the set of all its attributes A superkey can have redundant attributes, so a more useful concept is that of a KEY which has no redundancy Key satisfies theconstrains: Two tuples in the relation cannot have identical values for the attributes in the key It is a minimal superkey In general, a relation schema may have more than one key, in this case, each of the key is called a candidate key If a relation has several candidate keys, one is chosen to be the primary key.

Key Constraints Foreign key : Set of fields in one relation that is used to ‘ refer ’ to a tuple in another relation (Must correspond to primary key of the second relation.) If all foreign key constraints are enforced, referential integrity is achieved

Example: Consider ER Model consisting of entities Movies and Stars How to translate ER model to Relational Model? title year length id name StarMovies Stars-in filmType Character dateOfBirth

Entity set to relation Map each entity set to a relation, the key to primary key How would you define relations for entity sets Movies and Star ? - Assume, No two movies with same name have same year or length. title year length Movies filmType id name Star dateOfBirth

Entity set to relation Map each entity set to a relation, the key to primary key - Assume, No two movies with same name have same year or length. - (title, year) and (title, length) form candidate keys. CREATE TABLE Movies ( title CHAR(30), year INTEGER, length INTEGER, PRIMARY KEY ( title, year ), UNIQUE (title, length) ) CREATE TABLE Star ( id INTEGER, dateOfBirth CHAR(20), PRIMARY KEY ( name ) ) title year length Movies filmType id name Star dateOfBirth

Relationships to relations In translating a relationship set to a relation, attributes of the relation must include: Keys for each participating entity set (as foreign keys-explained later) This set of attributes forms a superkey for the relation All descriptive attributes How would you translate the relation Stars-In to a relation? What are the constraints? title year length id name StarMovies Stars-in filmType Character dateOfBirth

Relationships to relations Recall, Foreign key : Set of fields in one relation that is used to ‘ refer ’ to a tuple in another relation. CREATE TABLE Stars-In ( id INTEGER, title CHAR(30), year INTEGER, character CHAR(30), PRIMARY KEY ( id, title, year ) FOREIGN KEY ( id ) REFERENCES Star(id), FOREIGN KEY ( title ) REFERENCES Movies(title), FOREIGN KEY ( year ) REFERENCES Movies(year) ) title year length id name StarMovies Stars-in filmType Character dateOfBirth

Thank You!