









Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!










The Entity-Relationship Model -- 1
The Entity-Relationship Model -- 2 C SC 343 -- Introduction to Databases
The Entity-Relationship Model -- 3 Textbook Notation
Person Residence (^) City The Entity-Relationship Model -- 4 C SC 343 -- Introduction to Databases Examples of Keys (internal) single-attribute key (unary key) AUTOMOBILE Registration Model Color Slides Part 1 (UML inspired) notation Text notation
The Entity-Relationship Model -- 7 An Entity Hierarchy isA isA isA isA isA The Entity-Relationship Model -- 8 C SC 343 -- Introduction to Databases
Aggregation
The Entity-Relationship Model -- 9 An Example pid did budget started_on pbudget dname until Projects Sponsors Departments Employees Monitors lot name ssn since
(0,1) The Entity-Relationship Model -- 10 C SC 343 -- Introduction to Databases Conceptual Design Using the ER Model Design choices: Should a concept be modeled as an entity or an attribute? Should a concept be modeled as an entity or a relationship? Identifying relationships: Binary or ternary? Aggregation? Note constraints of the ER Model: A lot of data semantics can (and should) be captured. But some constraints cannot be captured in ER diagrams. We’ll refine things in our logical (relational) design
The Entity-Relationship Model -- 13 Entity vs. Relationship OK as long as a manager gets a separate discretionary budget ( dbudget ) for each dept. What if manager’s dbudget covers all managed depts? (can repeat value, but such redundancy is problematic) Manages name dname did budget Employees Departments ssn lot since dbudget Employees since name dname did budget Departments ssn lot Mgr_Appts is_manager dbudget apptnum managed_by The Entity-Relationship Model -- 14 C SC 343 -- Introduction to Databases Now you try it Courses database: Courses, Students, Professors Courses have ids, titles, credits. The id is unique. Courses have multiple sections that have time, a room and exactly one teacher Professors have a unique name Students take courses and receive a grade Students may repeat a course Must track students’ course schedules and transcripts including grades, semester taken, etc. Must track which classes a professor has taught Database should work over multiple semesters
The Entity-Relationship Model -- 15 Summary of Conceptual Design Conceptual design follows requirements analysis , Yields a high-level description of data to be stored ER model popular for conceptual design Constructs are expressive, close to the way people think about their applications. Note: There are many variations on ER model Both graphically and conceptually Basic constructs: entities , relationships , and attributes (of entities and relationships). Some additional constructs: weak entities , ISA hierarchies , and aggregation****. The Entity-Relationship Model -- 16 C SC 343 -- Introduction to Databases Summary of ER (Cont.)
The Entity-Relationship Model -- 19 Logical DB Design: ER to Relational Entity sets to tables. CREATE TABLE Employees (ssn CHAR(11), name CHAR(20), lot INTEGER, PRIMARY KEY (ssn)) Employees ssn name lot ssn name lot 123-22-3666 Attishoo 48 231-31-5368 Smiley 22 131-24-3650 Smethurst 35 The Entity-Relationship Model -- 20 C SC 343 -- Introduction to Databases Relationship Sets to Tables In translating a many-to-many relationship set to a relation, attributes of the relation must include: Keys for each participating entity set (as foreign keys).
All descriptive attributes. CREATE TABLE Works_In( ssn CHAR(1), did INTEGER, since DATE, PRIMARY KEY (ssn, did), FOREIGN KEY (ssn) REFERENCES Employees, FOREIGN KEY (did) REFERENCES Departments)
The Entity-Relationship Model -- 21 Review: Key Constraints Each dept has at most one manager, according to the key constraint on Manages. Translation to relational model? 1-to-1 1-to-Many Many-to-1 Many-to-Many dname did^ budget since lot name ssn Employees (^) Manages Departments Alternative notation: (0,N) left, (0, 1) right The Entity-Relationship Model -- 22 C SC 343 -- Introduction to Databases
Map relationship set to a table: Note that did is the key now! Separate tables for Employees and Departments. Since each department has a unique manager, we could instead combine Manages and Departments. CREATE TABLE Manages( ssn CHAR(11), did INTEGER, since DATE, PRIMARY KEY (did), FOREIGN KEY (ssn) REFERENCES Employees, FOREIGN KEY (did) REFERENCES Departments) CREATE TABLE Dept_Mgr( did INTEGER, dname CHAR(20), budget REAL, ssn CHAR(11), since DATE, PRIMARY KEY (did), FOREIGN KEY (ssn) REFERENCES Employees)
The Entity-Relationship Model -- 25 Participation Constraints in SQL
CREATE TABLE Dept_Mgr( did INTEGER, dname CHAR(20), budget REAL, ssn CHAR(11) NOT NULL, since DATE, PRIMARY KEY (did), FOREIGN KEY (ssn) REFERENCES Employees, ) The Entity-Relationship Model -- 26 C SC 343 -- Introduction to Databases Review: Weak Entities A weak entity can be identified uniquely only by considering the primary key of another ( owner ) entity. Owner entity set and weak entity set must participate in a one-to- many relationship set (1 owner, many weak entities). Weak entity set must have total participation in this identifying relationship set. lot name pname age Employees^ Dependents ssn Policy cost
The Entity-Relationship Model -- 27 Translating Weak Entity Sets Weak entity set and identifying relationship set are translated into a single table. When the owner entity is deleted, all owned weak entities must also be deleted. CREATE TABLE Dep_Policy ( pname CHAR(20), age INTEGER, cost REAL, ssn CHAR(11) NOT NULL, PRIMARY KEY (pname, ssn), FOREIGN KEY (ssn) REFERENCES Employees, ON DELETE CASCADE) The Entity-Relationship Model -- 28 C SC 343 -- Introduction to Databases Review: ISA Hierarchies Attributes are inherited From superclass 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) Contract_Emps name ssn Employees lot hourly_wages ISA Hourly_Emps contractid hours_worked
The Entity-Relationship Model -- 31 Binary vs. Ternary Relationships (Contd.) The key constraints allow us to combine Purchaser with Policies and Beneficiary with Dependents. P a r t i c i p a t i o n constraints lead to NOT NULL constraints. CREATE TABLE Policies ( policyid INTEGER, cost REAL, ssn CHAR(11) NOT NULL, PRIMARY KEY (policyid). FOREIGN KEY (ssn) REFERENCES Employees, ON DELETE CASCADE) CREATE TABLE Dependents ( pname CHAR(20), age INTEGER, policyid INTEGER, PRIMARY KEY (pname, policyid). FOREIGN KEY (policyid) REFERENCES Policies, ON DELETE CASCADE) The Entity-Relationship Model -- 32 C SC 343 -- Introduction to Databases ER Model Summary