Download presentation
Presentation is loading. Please wait.
1
The Entity-Relationship Model
Relational Thinking Demo some ER drawing tools, see wikipedia. To demo SQL server on CSIL: log in, choose Cypress (not SQL-Lite). Choose SQL Server login. Look up user name, password from helpdesk, something like s_oschulte. Chapter 1: Introduction to Database Systems Chapter 2: The Entity-Relationship Model Chapter 3: The Relational Model Chapter 4 (Part A): Relational Algebra Chapter 4 (Part B): Relational Calculus Chapter 5: SQL: Queries, Programming, Triggers Chapter 6: Query-by-Example (QBE) Chapter 7: Storing Data: Disks and Files Chapter 8: File Organizations and Indexing Chapter 9: Tree-Structured Indexing Chapter 10: Hash-Based Indexing Chapter 11: External Sorting Chapter 12 (Part A): Evaluation of Relational Operators Chapter 12 (Part B): Evaluation of Relational Operators: Other Techniques Chapter 13: Introduction to Query Optimization Chapter 14: A Typical Relational Optimizer Chapter 15: Schema Refinement and Normal Forms Chapter 16 (Part A): Physical Database Design Chapter 16 (Part B): Database Tuning Chapter 17: Security Chapter 18: Transaction Management Overview Chapter 19: Concurrency Control Chapter 20: Crash Recovery Chapter 21: Parallel and Distributed Databases Chapter 22: Internet Databases Chapter 23: Decision Support Chapter 24: Data Mining Chapter 25: Object-Database Systems Chapter 26: Spatial Data Management Chapter 27: Deductive Databases Chapter 28: Additional Topics 1
2
Overview Relational Model Entity-Relationship Diagrams. Motivation.
Definition. Entity-Relationship Diagrams. Key Constraints. Participation Constraints. Weak Entities. ISA Hierarchy.
3
Relational Databases: History
1970s: Computers are spreading. Many organizations use them to store their data. Ad hoc formats hard to build general data management systems. lots of duplicated effort. The Standardization Dilemma: Too restrictive: doesn’t fit users’ needs. Too loose: back to ad-hoc solutions.
4
The Relational Format Codd (IBM Research 1970)
The fundamental question: What kinds of information do users need to represent? Answered by 1st-order predicate logic! (Russell, Tarski). The world consists of Individuals/entities. Relationships/links among them.
5
Database design
6
Gathering Specifications
The slides for this text are organized into chapters. This lecture covers Chapter 5. Chapter 1: Introduction to Database Systems Chapter 2: The Entity-Relationship Model Chapter 3: The Relational Model Chapter 4 (Part A): Relational Algebra Chapter 4 (Part B): Relational Calculus Chapter 5: SQL: Queries, Programming, Triggers Chapter 6: Query-by-Example (QBE) Chapter 7: Storing Data: Disks and Files Chapter 8: File Organizations and Indexing Chapter 9: Tree-Structured Indexing Chapter 10: Hash-Based Indexing Chapter 11: External Sorting Chapter 12 (Part A): Evaluation of Relational Operators Chapter 12 (Part B): Evaluation of Relational Operators: Other Techniques Chapter 13: Introduction to Query Optimization Chapter 14: A Typical Relational Optimizer Chapter 15: Schema Refinement and Normal Forms Chapter 16 (Part A): Physical Database Design Chapter 16 (Part B): Database Tuning Chapter 17: Security Chapter 18: Transaction Management Overview Chapter 19: Concurrency Control Chapter 20: Crash Recovery Chapter 21: Parallel and Distributed Databases Chapter 22: Internet Databases Chapter 23: Decision Support Chapter 24: Data Mining Chapter 25: Object-Database Systems Chapter 26: Spatial Data Management Chapter 27: Deductive Databases Chapter 28: Additional Topics
7
Overview of Database Development
Requirements Analysis / Ideas High-Level/Conceptual Database Design Conceptual/Relational Database Schema Dilbert on software requirements Physical Database Design Similar to software development 2
8
Overview of Database Design
Conceptual design: (ER Model is used at this stage.) 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? An ER Model can be represented pictorially (ER diagrams). Can map an ER diagram into a relational schema. Can also Unified Modelling Language (UML). Pictorial Versions of 1st-order logic. 2
9
Entity-Relationship Models
10
Employees ssn name lot Entities Entity: Real-world object distinguishable from other objects. An entity is described using a set of attributes. Entity Set: A collection of similar entities. E.g., all employees. All entities in an entity set have the same set of attributes. (Exception: ISA hierarchies, later.) Each entity set has a key. Each attribute has a domain. A key can be a (minimal) set of attributes. An entity set is like a class, an entity is like an instance. 3
11
Example: Entities ssn name lot 1000 Atishoo 1 2000 Maite 2 .... Cecile
violates attribute key constraint Employees ssn name lot
12
Relationships s Users Receiver Sender id lot dname budget did since name Works_In Departments Employees ssn Relationship: Association among two or more entities. E.g., Attishoo works in Pharmacy department. Relationship Set: Collection of similar relationships. An n-ary relationship set R relates n entity sets E1 ... En; each relationship in R involves entities e1, ..., en. Same entity set could participate in different relationship sets, or in different “roles” in same set. Consider showing Tarki’s workld demo. 4
13
Example: Relationships
s Users Receiver Sender id Relationships .... lot dname budget did since name Works_In Departments Employees ssn Relationships Attribute Values <Attishoo, Pharmacy> 2000 <Cecile, Reception> 2010 .... 2011 disallowed
14
Relation Math
15
Cartesian or Cross-Products
A tuple <a1,a2,…,an> is just a list with n elements in order. A binary tuple <a,b> is called an ordered pair. Given two sets A,B, we can form a new set A x B containing all ordered pairs <a,b> such that a is a member of A, b is a member of B. In set notation: A x B = {<a,b> | a in A, b in B}. Example: {1,2,3} x {x,y} = {<1,x>,<1,y>,<2,x>,<2,y>,<3,x>,<3,y>}
16
Exercise Let A = {1,2,3}, B = {x,y}. Compute B x A. Compute A x A.
17
N-fold cross products Given n sets A1, A2, …, An, the cross product A1 x A2 x A3 …x An is a new set defined by A1 x A2 x A3 …x An = {<a1, a2, a3, …, an>: a1 in A1, a2 in A2, …, an in An}. Example: {1,2,3} x {x,y} x {1,2,3} has as members <1,x,1> and <1,y,3>.
18
Exercise Let A = {1,2,3}, B = {x,y}. Compute B x A x B.
Compute B x B x B. If a set C has n members, how many are there in C x C? How many in C x C x C? In general, how many in C x C x …x C where we take k cross-products? SQL implements these in one line.
19
The Cross Product Let E1, E2, E3 be three entity sets.
A relationship among E1, E2, E3 is a tuple in E1 x E2 x E3. A relationship set is a set of relationships. So if R is a relationship set among E1, E2, E3, then R is a subset of E1 x E2 x E3. Relationship set = subset of cross product.
20
Relationships A relationship defines a relationship set given entity sets. Informally, the relationship specifies which entities are related. entityset 1 entityset 2 Students Courses Relationship Enrolled Relationship Set enrolled (student,course) subset subset entityset 1 x entityset 2 Students x Course
21
ER Diagrams and Relation Constraints
22
Relation Types since lot name ssn dname did budget Manages Consider Works_In: An employee can work in many departments; a dept can have many employees. In contrast, each dept has at most one manager, according to the key constraint on Manages. Employees Departments Examples: 1-1 -> Dep, Manager 1-many -> Dep, Employees Many-1 -> Employees, Dep Many-Many -> Customers, Items. Who can come up with another example? 1-to-1 1-to Many Many-to-1 Many-to-Many 6
23
ER Exercise 1 A university database contains information about professors (identified by SSN) and courses (identified by courseid). Professors teach courses; each of the following situations concerns the Teaches relationship. For each diagram, draw an ER diagram that describes it (assuming no further constraints hold). Professors can teach the same course in several semesters, and only the most recent such offering needs to be recorded. Professors can teach the same course in several semesters, and each offering must be recorded.
24
Participation Constraints
Must every department have a manager? If so, this is a participation constraint: the participation of Departments in Manages is said to be total (vs. partial). Every did value in Departments must appear in a tuple of the Manages relation. since since name name dname dname ssn lot did did budget budget Employees Manages Departments Works_In since 8
25
Example: Participation Constraint
Manages Relationship since <1000,100> 2000 <2000,200> 2001 participation constraint requires entry for did 300 Departments did dname budget 100 CS 1M 200 Biology 10M 300 Engineering 100M
26
ER Exercise ctd. Same scenario as before, where we need only the current semester. Draw E-R diagrams for the following constraints. 3. Every professor must teach some course. 4. Every professor teaches exactly one course. 5. Every professor teaches exactly one course, and every course must be taught by some professor. Prepare solutions. in ex 2.2.
27
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 (one owner, many weak entities). Weak entity set must have total participation in this identifying relationship set. login name filename Assignment Students sid Submits grade submit time Nice example: each student submits an assignment file, called solutions.pdf. This is a partial ID, works only in conjunction with student ID. 10
28
Example: Weak Entities
Filename StudentID assign1.pdf 1000 2000 ....
29
ISA (is a) Hierarchies As in C++, or Java, attributes are inherited.
name ISA (is a) Hierarchies ssn lot Employees As in C++, or Java, attributes are inherited. If we declare A ISA B, every A entity is also considered to be a B entity. 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? (Overlap Allowed/disallowed) Covering constraints: Does every Employees entity also have to be an Hourly_Emps or a Contract_Emps entity? (Covering Yes/no) Reasons for using ISA: To add descriptive attributes specific to a subclass. To identify entities that participate in a relationship. Examples: hourly wages are specific to hourly employees “motor vehicles” participates in “licenses” relationship; see also managers in slide “entity vs. relationship”. What would you expect for overlap/covering constraints? 12
30
Reading Review Question
A ternary relationship has three attributes connects three entity sets contains a key constraint.
31
Designing ER Diagrams show Mondial ER diagaam: things can get complicated, better fix schema before moving data. See monial-abh.pdf for tabular schema. Also: example from soccer from premier league. Example: entities = {match, players, teams}. Relationships: Plays(Team,Match), Home(Team, Match), PlaysIn(Player,Team), PlaysIn(Player,Match).
32
Conceptual Design Using the ER Model
Design choices: Should a concept be modeled as an entity or an attribute? (e.g., address) Should a concept be modeled as an entity or a relationship? (e.g., address) Identifying relationships: Binary or ternary? These are common for relational databases. 3
33
Entity vs. Attribute Should address be an attribute of Employees or an entity (connected to Employees by a relationship)? Depends upon the use we want to make of address information: If we have several addresses per employee, address must be an entity. (Why?) If the structure (city, street, etc.) is important, e.g., we want to retrieve employees in a given city, address must be modeled as an entity (since attribute values are atomic). On atomic values: that’s the top of the object-oriented iceberg. several addresses: (since attributes cannot be set-valued)
34
Entity vs. Attribute (Contd.)
from to name Employees ssn lot dname Works_In4 does not allow an employee to work in a department for two or more periods. Similar to the problem of wanting to record several addresses for an employee: We want to record several values of the descriptive attributes for each instance of this relationship. Accomplished by introducing new entity set, Duration. did budget Works_In4 Departments dname budget did name Departments ssn lot Employees Works_In5 Duration from to General point: reify space and time points. 5
35
Duration Example Relationships <Attishoo, Pharmacy, 2000-2001>
dname budget did name Departments ssn lot Employees Works_In5 Duration from to Relationships <Attishoo, Pharmacy, > <Cecile, Reception, > .... <Cecile, Reception, >
36
Entity vs. Relationship
First ER diagram OK if a manager gets a separate discretionary budget for each dept. What if a manager gets a discretionary budget that covers all managed depts? Redundancy: dbudget stored for each dept managed by manager. Misleading: Suggests dbudget associated with department-mgr combination. Manages2 name dname budget did Employees Departments ssn lot dbudget since Departments dname budget did Manages2 Employees name ssn lot since Managers dbudget ISA what are the differences between the two E-R diagrams? (Before showing the text.) This fixes the problem! 6
37
Binary vs. Ternary Relationships
age pname Dependents Covers name ssn lot Employees Policies policyid cost Bad design If each policy is owned by just 1 employee, and each dependent is tied to the covering policy, first diagram is inaccurate. Beneficiary age pname Dependents policyid cost Policies Purchaser name Employees ssn lot Better design what are the differences between the two E-R diagrams? (Before showing the text.) For each dependent, exactly one policy of which the dependent is the beneficiary. For each policy, there is exactly one employee who purchases it. 7
38
Binary vs. Ternary Example
Covers Ternary Relationships <Employee,Policy,Dependent> <Maite,100E,Adriana> <Oliver,100E,Adriana> <Juan,200A,Adriana> Beneficiary Purchases Binary Relationships <Policy,Dependent> <100E,Adriana> <200A,Adriana> Binary Relationships <Employee,Policy> <Maite,100E> <Oliver,100E> <Juan,200A>
39
Binary vs. Ternary Relationships (Contd.)
Previous example: two binary relationships were better than one ternary relationship. An example in the other direction: a ternary relation Contracts relates entity sets Parts, Departments and Suppliers, and has descriptive attribute qty. No combination of binary relationships is an adequate substitute. Need to be able to accommodate any triple -> no constraints to exploit in modelling. : S “can-supply” P, D “needs” P, and D “deals-with” S does not imply that D has agreed to buy P from S. How do we record qty? 9
40
Summary
41
Conceptual Design Conceptual design follows requirements analysis,
Provides a high-level description of data to be stored. ER model popular for conceptual design Expressive constructs. Close to the way users think about their domains. Basic constructs: entities, relationships, and attributes. Some additional constructs: weak entities, ISA hierarchies. There are many variations on ER model. 11
42
Constraints in the ER Model
Several kinds of integrity constraints can be expressed in the ER model. key constraints. participation constraints. overlap/covering constraints for ISA hierarchies. Some constraints (notably, functional dependencies) cannot be expressed in the ER model. (e.g., z = x + y) Constraints play an important role in determining the best database design for an enterprise. 12
43
Common Design Choices ER design is subjective. Common choices include:
There are often many ways to model a given scenario Analyzing alternatives can be tricky, especially for a large enterprise. Common choices include: Entity vs. attribute. entity vs. relationship binary or n-ary relationship ISA hierarchies. Resulting relational schema should be analyzed and refined further. FD = functional dependency. Normalization: automatically simplify schema. These are not part of our course. 13
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.