CS422 Principles of Database Systems Convert ER Design to Relations Chengyu Sun California State University, Los Angeles.

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

Convert ER to Relational Database Entity relation Entity relation Attributes attributes Attributes attributes Primary key primary key Primary key primary.
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.
Weak Entity Sets An entity set that does not have a primary key is referred to as a weak entity set. The existence of a weak entity set depends on the.
Entity-Relationship Model and Diagrams (continued)
Database Design Chapter 2. Goal of all Information Systems  To add value –Reduce costs –Increase sales or revenue –Provide a competitive advantage.
Chapter 4 Relational Databases Copyright © 2012 Pearson Education, Inc. publishing as Prentice Hall 4-1.
©Silberschatz, Korth and Sudarshan2.1Database System Concepts Reduction of an E-R Schema to Tables A database which conforms to an E-R diagram can be represented.
Chapter 4 Relational Databases Copyright © 2012 Pearson Education 4-1.
Introduction to Databases
IST Databases and DBMSs Todd S. Bacastow January 2005.
 Keys are special fields that serve two main purposes: ◦ Primary keys are unique identifiers of the relation in question. Examples include employee numbers,
The Relational Database Model
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 Design Concepts
Module Title? DBMS E-R Model to Relational Model.
DATABASE MANAGEMENT SYSTEMS BASIC CONCEPTS 1. What is a database? A database is a collection of data which can be used: alone, or alone, or combined /
DATABASE MANAGEMENT SYSTEMS BASIC CONCEPTS 1. What is a database? A database is a collection of data which can be used: alone, or alone, or combined /
Web-Enabled Decision Support Systems
CHAPTER 8: MANAGING DATA RESOURCES. File Organization Terms Field: group of characters that represent something Record: group of related fields File:
RELATIONSHIPS Generally there are two main database types: flat-file and relational.
Chapter 3: Relational Model I Structure of Relational Databases Structure of Relational Databases Convert a ER Design to a Relational Database Convert.
R ELATIONAL D ATA M ODEL Joe Meehean 1. R ELATIONAL D ATA M ODEL Data stored as a set of relations really just tables Tables related to one another through.
Normalization (Codd, 1972) Practical Information For Real World Database Design.
Chapter 3: Relational Model  Structure of Relational Databases  Normal forms (chap. 7)  Reduction of an E-R Schema to Relational (Sect. 2.9)  Relational.
Databases. Not All Tables Are Created Equal Spreadsheets use tables to store data and formulas associated with that data The “meaning” of data is implicit.
Relational Databases CPSC 315 – Programming Studio Spring 2013 Project 1, Lecture 2 Slides adapted from those used by Jeffrey Ullman, via Jennifer Welch.
EXAMPLE. Subclasses and Superclasses Entity type may have sub-grouping that need to be represented explicitly. –Example: Employee may grouped into.
1 Database & DBMS The data that goes into transaction processing systems (TPS), also goes to a database to be stored and processed later by decision support.
1 © Prentice Hall, 2002 Chapter 5: Logical Database Design and the Relational Model Modern Database Management 6 th Edition Jeffrey A. Hoffer, Mary B.
Access Review. Access Access is a database application A database is a collection of records and files organized for a particular purpose Access supports.
© D. Wong Ch. 2 Entity-Relationship Data Model (continue)  Data models  Entity-Relationship diagrams  Design Principles  Modeling of constraints.
 Primary keys allow entity sets and relationship sets to be expressed uniformly as relations  E/R diagram  collection of tables  For each entity set.
ICOM 5016 – Introduction to Database Systems Lecture 9 Dr. Manuel Rodriguez Department of Electrical and Computer Engineering University of Puerto Rico,
Entity Relationship Diagram (2)
ENTITY RELATIONSHIP DIAGRAM ENTITY RELATIONSHIP DIAGRAM IS A SPECIALIZED GRAPHIC THAT ILLUSTRATES THE INTERRELATIONSHIPS BETWEEN ENTITIES IN A DATABASE.
Relational Theory and Design
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan Lecture-03 Introduction –Data Models Lectured by, Jesmin Akhter.
Chapter 2: Intro to Relational Model. 2.2 Example of a Relation attributes (or columns) tuples (or rows)
1 ER Modeling BUAD/American University Mapping ER modeling to Relationships.
* Database is a group of related objects * Objects can be Tables, Forms, Queries or Reports * All data reside in Tables * A Row in a Table is a record.
Rensselaer Polytechnic Institute CSCI-4380 – Database Systems David Goldschmidt, Ph.D.
Jennifer Widom Relational Databases The Relational Model.
Howard Paul. Sequential Access Index Files and Data File Random Access.
CHAPTER 2 : RELATIONAL DATA MODEL Prepared by : nbs.
COMP 430 Intro. to Database Systems ER Implementation as Tables Slides use ideas from Chris Ré.
FEN Introduction to the database field: The development process Seminar: Introduction to relational databases Development process: Analyse.
CS320 Web and Internet Programming SQL and MySQL Chengyu Sun California State University, Los Angeles.
CS422 Principles of Database Systems Entity-Relationship Model Chengyu Sun California State University, Los Angeles.
High-level Database Models Prof. Yin-Fu Huang CSIE, NYUST Chapter 4.
Rationale Databases are an integral part of an organization. Aspiring Database Developers should be able to efficiently design and implement databases.
IT 5433 LM3 Relational Data Model. Learning Objectives: List the 5 properties of relations List the properties of a candidate key, primary key and foreign.
XP Chapter 1 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach 1 Level 2 Objectives: Understanding and Creating Table.
CS422 Principles of Database Systems From ER to Relations Chengyu Sun California State University, Los Angeles Adapted from Jeffrey Ullman’s lecture notes.
CS422 Principles of Database Systems Entity-Relationship Model
CS320 Web and Internet Programming SQL and MySQL
CS422 Principles of Database Systems Course Overview
CSCI-100 Introduction to Computing
Chapter 4 Relational Databases
Translation of ER-diagram into Relational Schema
Entity-Relationship Model and Diagrams (continued)
Normalization Referential Integrity
Relational Databases The Relational Model.
Relational Databases The Relational Model.
Session 2 Welcome: The seventh learning sequence
Chengyu Sun California State University, Los Angeles
CS3220 Web and Internet Programming SQL and MySQL
CS3220 Web and Internet Programming SQL and MySQL
Session 5: Weak Entity Sets and ER Model to Relational ( )
Presentation transcript:

CS422 Principles of Database Systems Convert ER Design to Relations Chengyu Sun California State University, Los Angeles

Relational Model Proposed by Edgar F. Codd in early 1970’s Data is stored in tables (a.k.a. relations) All major database systems these day are relational student_idfirst_namelast_namebirthday JohnDoe JaneDoe TomSmith

Table (Relation) idname 1000John 1001Jane Attributes (fields, columns) Records (Rows) (Tuples) Students

Table and Database Schema Table schema Name of the table, and the names and types of the attributes E.g. students(id:integer,name:string) or just students(id,name) Database schema Schemas of all the tables in the database

About Relational Model Attributes must be of simple type No order among attributes No order among records

From ER to Relations … Classes name Departments name Students name addr TakeOffer id codequarter section

… From ER to Relations Students ( id, name, address ) Departments ( name ) Classes ( code, name, quarter, section, department_name ) Enrollment ( code, quarter, section, student_id )

Basic Rules of ER to Relational Conversion … A entity set is converted to a table Entity set name  table name Entity set attributes  table columns Entity set key  table key A many-to-many relationship is also converted to a table, including Its own attributes (if any) Key attributes from the associated entity sets  table key

… Basic Rules of ER to Relational Conversion A many-to-one relationship is converted to a foreign key column on the “many” side referencing the “one” side ClassesDepartments Offer Classes ( code, name, quarter, section, department_name )

About Keys: Primary Key Entity set key: an attribute or a combination of several attributes that uniquely identifies an entity Primary key in relational model: UNIQUE + NOT NULL

About Keys: Foreign Key Foreign key in relational model A link (or association) between two tables – a foreign key column is like an object reference in a Java class A data integrity constraint There is NO foreign key in ER model, because the association is already expressed as a relationship

Another Common Problem in ER Design Classes code Departments name Students name addr TakeOffer id department_name student_id class_id

More Conversion Examples ClassesStudents Take Grade Employees Supervise supervisoremployee idnameidcode idname

Basic ER to Relational Conversion Steps Step 1: convert entity sets to tables Step 2: convert relationships Many-to-many  table Many-to-one  foreign key column Step 3: rename tables and columns when necessary

Special Cases of Conversion One-to-One relationship Multiway relationship Weak entity set Subclass

Converting One-to-One Relationship … DepartmentsFaculty Chair nameidnameid

… Converting One-to-One Relationship Which one of the following is better?? Faculty( id, name, chair_of_department ) Departments( id, name ) Faculty( id, name ) Departments( id, name, department_chair ) or

Converting Multiway Relationship Should this relationship be treated as many- to-many or many-to-one?? ClassesStudents Take Grades codeidnameid lettergrade_point

Converting Weak Entity Set … The table for a weak entity set includes its complete key as well as it’s own non- key attributes A supporting relationship is redundant and yields no relation

… Converting Weak Entity Set PlayersTeams Play-on name numberlocation ??

Converting Subclass … Users Students isa idname cin

… Converting Subclass Object-oriented approach One table per concrete class Each entity belongs to exact one table ER approach One table per subclass Each entity may appear in multiple tables NULL approach One table per class hierarchy

Object-Oriented Approach idname 1000John Users idnamecin 1001Jane Students

ER Approach idname 1000John 1001Jane Users user_idcin Students

NULL Approach … idnamecin 1000JohnNULL 1001Jane Users

… NULL Approach iduser_typenamecin 1000staffJohnNULL 1001studentJane Users Discriminator field

Comparison of Subclass Conversion Approaches Constraints and data integrity Query performance Q1: list all students Q2: list all non-student users Q3: list all users

Example 1: Restaurant Some Restaurant #42 Date: Jul 09, 2008 Server: John Bill: 0060 Time: 03:07PM # of Guest: 2 Table: 42 1 Boiled Pork Wanton 1 Dumpling w/Crabmeat 1 Beef Noodle Soup Subtotal: GST: Total: Open Time: Jul 09, :57PM Printed by: Cashier

Example 2: Folders and Files C:\ \WINNT\Document and Settings\Program Files \cysun \database material\web material file1file2file3file4

Example 3: Price Changes Products idpricedescription What if we want to model price changes?? Price of a product X $ time