12 Entity Relationship Model
-
Upload
nathan-wilson -
Category
Documents
-
view
28 -
download
2
Transcript of 12 Entity Relationship Model
-
1
CS 338: Computer Applications in Business: Databases (Fall 2014)
1992-2014 by Addison Wesley & Pearson Education, Inc., McGraw Hill, Cengage Learning Slides adapted and modified from Fundamentals of Database Systems (5/6) (Elmasri et al.), Database System Concepts (5/6) (Silberschatz et al.), Database Systems (Coronel et al.), Database Systems (4/5) (Connolly et al. ), Database Systems: Complete Book (Garcia-Molina et al.)
CS 338: Computer Applications in Business: Databases
The Entity-Relationship (ER) Model
1992-2014 by Addison Wesley & Pearson Education, Inc., McGraw Hill, Cengage Learning Slides adapted and modified from Fundamentals of Database Systems (5/6) (Elmasri et al.), Database System Concepts (5/6) (Silberschatz et al.), Database Systems (Coronel et al.), Database Systems (4/5) (Connolly et al. ), Database Systems: Complete Book (Garcia-Molina et al.) Rice University Data Center
Fall 2014
Chapter 7
Phases of Database Design
Generally, the term database application refers to a particular database and the associated programs that implement the database queries and updates Traditionally, design of application programs is typically covered in
software engineering courses
3
Conceptual Modeling is a very important phase in designing a successful database application
Lets consider the process whereby a new database, such as our company database is created. Where do we begin? We begin with a design phase in which we address and answer questions about what information will be stored, how information elements will be related to one another, what constraints such as keys or referential integrity may be assumed, among others.
consider this
ideas High-Level Design
Relational Database Schema
Relational DBMS
-
2
CS 338: Computer Applications in Business: Databases (Fall 2014)
1992-2014 by Addison Wesley & Pearson Education, Inc., McGraw Hill, Cengage Learning Slides adapted and modified from Fundamentals of Database Systems (5/6) (Elmasri et al.), Database System Concepts (5/6) (Silberschatz et al.), Database Systems (Coronel et al.), Database Systems (4/5) (Connolly et al. ), Database Systems: Complete Book (Garcia-Molina et al.)
Phases of Database Design
ER diagrams is diagrammatic notation associated with the ER model
4
Entity-Relationship (ER) model is a popular high-level conceptual data model used for the conceptual design of database applications
1. Requirements Collection and Analysis Database designers interview prospective database users to understand and document data
requirements Result: set of user requirements (should be as detailed as possible) In parallel, it is useful to specify the known functional requirements of the application
2. Conceptual Database Design Detailed description of the data requirements (components and constraints) Result: conceptual schema in a high-level, conceptual data model
3. Logical Database Design (or Data Model Mapping) Transform the conceptual model into implementation data model Most commercial DBMSs use an implementation data model (e.g. relational or object-relational) Result: Database schema in implementation data model of DBMS
4. Physical Database Design Internal storage structures, file organizations, indexes, access paths, and physical design
parameters for the database files
Steps in Database Design
Sample Database Application: COMPANY
5
COMPANY database keeps track of employees, departments and projects 1. Company is organized into departments
Each department has a unique name, a unique number, and a particular employee who manages the department
Keep track of the start date when the employee began managing the department A department may have several locations
2. A department controls a number of projects Each project has a unique name, a unique number, and a single location
3. Employee: require each employees Social Security Number, name, address, salary, gender, and birth date An employee is assigned to one department, but may work on several projects (which
are not necessarily controlled by the same department) Keep track of the current number of hours per week that an employee works on each
project Also keep track of the direct supervisor of each employee (who is another employee)
4. Keep track of the dependents of each employee for insurance purposes Keep track of the dependents first name, sex, birth date, and relationship to the
employee
Requirements gathered for COMPANY
-
3
CS 338: Computer Applications in Business: Databases (Fall 2014)
1992-2014 by Addison Wesley & Pearson Education, Inc., McGraw Hill, Cengage Learning Slides adapted and modified from Fundamentals of Database Systems (5/6) (Elmasri et al.), Database System Concepts (5/6) (Silberschatz et al.), Database Systems (Coronel et al.), Database Systems (4/5) (Connolly et al. ), Database Systems: Complete Book (Garcia-Molina et al.)
ER Model Overview Three Principal Element Types
6
An entity is an abstract object of some sort Example: Person, Car, House, Employee A collection of similar entities forms an entity set
Entities and Entity Sets
Let us consider the design of our running company-database example. Each department is an entity, and the set of all departments constitutes an entity set. Likewise, the employees are entities, and the set of employees is an entity set. A project is another entity and the set of projects is a third entity set.
Example 1
Each entity has attributes the particular properties that describe it Example: an employee entity may be described by the employees name, age, address,
and position A particular entity will have a value for each of its attributes the attribute values that
describe each entity become a major part of the data stored in the database
Attributes
Relationships are connections among two or more entity sets Example: If Employee(s) and Department(s) are two entity sets, we could have a
relationship Works-for that connects employee and department
Relationships
Entities and Attributes Example
7
-
4
CS 338: Computer Applications in Business: Databases (Fall 2014)
1992-2014 by Addison Wesley & Pearson Education, Inc., McGraw Hill, Cengage Learning Slides adapted and modified from Fundamentals of Database Systems (5/6) (Elmasri et al.), Database System Concepts (5/6) (Silberschatz et al.), Database Systems (Coronel et al.), Database Systems (4/5) (Connolly et al. ), Database Systems: Complete Book (Garcia-Molina et al.)
Categories of Attributes
Simple (atomic) attributes vs. composite attributes
Single-valued attributes vs. multivalued attributes
Stored attributes vs. derived attributes
Key (or unique) attributes Attribute values constrained to be distinct for individual entities in
an entity set e.g. SSN
8
Categories of Attributes Composite vs. Simple (Atomic) Attributes
9
Can be divided into smaller subparts, which represent more basic attributes with independent meanings
Composite attributes can form a hierarchy: the value of a composite attribute is the concatenation of the values of its component simple attributes
If the composite attribute is referenced only as a whole, there is no need to subdivide it into component attributes
Composite Attributes
Attributes that are not divisible
Simple (Atomic) Attributes
Nathan WilsonSimple/composite:Deals with attribute type
Single/multivalued:Deals with attribute values
Stored/derived:Deals with how attribute value is obtained
-
5
CS 338: Computer Applications in Business: Databases (Fall 2014)
1992-2014 by Addison Wesley & Pearson Education, Inc., McGraw Hill, Cengage Learning Slides adapted and modified from Fundamentals of Database Systems (5/6) (Elmasri et al.), Database System Concepts (5/6) (Silberschatz et al.), Database Systems (Coronel et al.), Database Systems (4/5) (Connolly et al. ), Database Systems: Complete Book (Garcia-Molina et al.)
Categories of Attributes Single-valued vs. Multivalued Attributes
10
Most attributes have a single value for a particular entity Example: Age is a single-valued attribute of person
Single Attributes
In some cases, an attribute can have a set of values for the same entity Example: a Colors attribute for a car Example: Different people can have numbers of values for the College_degrees attribute Multivalued attribute can have lower and upper bounds to constrain the number of values
allowed for each individual entity Example: the Colors attribute of a car may be restricted to have between one and three
values (assuming that a car can have three colors at most)
Multivalued Attributes
Categories of Attributes Stored vs. Derived Attributes
11
In some cases, two (or more) attribute values are related
Consider Age and Birth_date attributes of a person The value of Age can be determined from the current (todays) date
and the value of that persons Birth_date
Age attribute is hence called a derived attribute and is said to be derivable from the Birth_date attribute, which is called a stored attribute
Some attribute values can be derived from related entities (Example: NumberOfEmployees)
Stored vs. Derived Attributes
-
6
CS 338: Computer Applications in Business: Databases (Fall 2014)
1992-2014 by Addison Wesley & Pearson Education, Inc., McGraw Hill, Cengage Learning Slides adapted and modified from Fundamentals of Database Systems (5/6) (Elmasri et al.), Database System Concepts (5/6) (Silberschatz et al.), Database Systems (Coronel et al.), Database Systems (4/5) (Connolly et al. ), Database Systems: Complete Book (Garcia-Molina et al.)
NULL Values
12
In some cases, a particular entity may not have an applicable value for an attribute
Example: ApartmentNumber attribute of an address applies only to
addresses that are in Apartment Buildings and NOT to other types of residences (i.e. house)
NULL Values
Entity Sets
13
Entity type (or entity set) Collection (or set) of similar entities that have the same attributes An entity type describes the schema or intension of a set of entities
that share the same structure The collection of entities of a particular entity type is grouped into an
entity set (also known as the extension of the entity type)
ER model defines entity sets, not individual entities But entity sets are described in terms of their attributes
-
7
CS 338: Computer Applications in Business: Databases (Fall 2014)
1992-2014 by Addison Wesley & Pearson Education, Inc., McGraw Hill, Cengage Learning Slides adapted and modified from Fundamentals of Database Systems (5/6) (Elmasri et al.), Database System Concepts (5/6) (Silberschatz et al.), Database Systems (Coronel et al.), Database Systems (4/5) (Connolly et al. ), Database Systems: Complete Book (Garcia-Molina et al.)
Displaying an Entity Type in ER Models
In ER diagrams, an entity type is displayed as a rectangular box enclosing entity name
Attributes are displayed as ovals Each attribute is
connected to its entity type by a straight line
Composite attributes are attached to their component attributes by straight lines
Multivalued attributes are displayed in double ovals
14
Sample Database Application: COMPANY Revisited
COMPANY database keeps track of employees, departments and projects 1. Company is organized into DEPARTMENTS
Each department has a unique name, a unique number, and a particular employee who manages the department.
Keep track of the start date when the employee began managing the department. A department may have several locations
2. A department controls a number of PROJECTS Each project has a unique name, a unique number, and a single location
3. EMPLOYEE: require each employees Social Security Number, name, address, salary, gender, and birth date An employee is assigned to one department, but may work on several projects (which
are not necessarily controlled by the same department) Keep track of the current number of hours per week that an employee works on each
project Also keep track of the direct supervisor of each employee (who is another employee)
4. Keep track of the DEPENDENTS of each employee for insurance purposes Keep track of the dependents first name, sex, birth date, and relationship to the
employee
Requirements gathered for COMPANY
15
-
8
CS 338: Computer Applications in Business: Databases (Fall 2014)
1992-2014 by Addison Wesley & Pearson Education, Inc., McGraw Hill, Cengage Learning Slides adapted and modified from Fundamentals of Database Systems (5/6) (Elmasri et al.), Database System Concepts (5/6) (Silberschatz et al.), Database Systems (Coronel et al.), Database Systems (4/5) (Connolly et al. ), Database Systems: Complete Book (Garcia-Molina et al.)
Sample Database Application: COMPANY Revisited
Based on the requirements, we can identify four initial entity types in the COMPANY database:
DEPARTMENT
PROJECT
EMPLOYEE
DEPENDENT
16
Initial ER Diagram for COMPANY
Four entity types
Most attributes are simple, single-valued, and stored Works_on and Locations are multivalued Employees name is composite
Employee has one key, dependent has none, department and project have two keys
17
-
9
CS 338: Computer Applications in Business: Databases (Fall 2014)
1992-2014 by Addison Wesley & Pearson Education, Inc., McGraw Hill, Cengage Learning Slides adapted and modified from Fundamentals of Database Systems (5/6) (Elmasri et al.), Database System Concepts (5/6) (Silberschatz et al.), Database Systems (Coronel et al.), Database Systems (4/5) (Connolly et al. ), Database Systems: Complete Book (Garcia-Molina et al.)
Weak Entity Types
Entity types that do not have key attributes of their own Identified by their relationship to specific entities from another entity type Weak entity types are represented by surrounding their boxes and diamonds with
double lines
Identifying relationship Relates a weak entity type to the identifying entity, which has the rest of the key
18
Dependent is meaningless in COMPANY DB independently of Employee
Identified by relationship to Employee
Dependent_name distinguishes one dependent from other dependents for the same employee: partial key
Sample Database Application: COMPANY Revisited
Initial design is typically not complete We have not represented that an employee can work on several
projects We have not represented the number of hours per week an
employee works on
Some aspects in the requirements will be represented as relationships Example: attribute Manager of DEPARTMENT refers to an
employee who manages the department Example: Controlling_department of PROJECT refers to the
department that controls the project
In the ER model, these references should not be represented as attributes but as relationships
19
-
10
CS 338: Computer Applications in Business: Databases (Fall 2014)
1992-2014 by Addison Wesley & Pearson Education, Inc., McGraw Hill, Cengage Learning Slides adapted and modified from Fundamentals of Database Systems (5/6) (Elmasri et al.), Database System Concepts (5/6) (Silberschatz et al.), Database Systems (Coronel et al.), Database Systems (4/5) (Connolly et al. ), Database Systems: Complete Book (Garcia-Molina et al.)
Relationships in General
Relationship An association (or interaction) between entities Indicator: an attribute of one entity refers to another entity Represent such references as relationships not attributes
Examples: EMPLOYEE John Smith Works on the ProductX PROJECT
20
Relationships
Relationship An association (or interaction) between entities Indicator: an attribute of one entity refers to another entity Represent such references as relationships not attributes
Relationship type R among n entity types E1, E2, ..., En Defines a set of associations among entities from these entity types
Relationship instance ri Each ri associates n individual entities (e1, e2, ..., en) Each entity ej in ri is a member of entity set Ej Relationships uniquely identified by keys of participating entities
Degree of a relationship type Number of participating entity types e.g., binary, ternary
21
-
11
CS 338: Computer Applications in Business: Databases (Fall 2014)
1992-2014 by Addison Wesley & Pearson Education, Inc., McGraw Hill, Cengage Learning Slides adapted and modified from Fundamentals of Database Systems (5/6) (Elmasri et al.), Database System Concepts (5/6) (Silberschatz et al.), Database Systems (Coronel et al.), Database Systems (4/5) (Connolly et al. ), Database Systems: Complete Book (Garcia-Molina et al.)
Degree of Relationship Examples
In ER diagrams, we represent the relationship type as follows
Diamond-shaped box is used to display a relationship type
Connected to the participating entity types via straight lines
22
Relationships with Repeated Entity Sets
23
Some relationships involve multiple entities from the same entity set e.g., spouse (two persons), games (two
teams) e.g., recursive relationships, such as
supervises (two employees)
Recursive relationships A relationship type with the same
participating entity type but in different roles
Role name Signifies role that participating entity
plays in relationship instance Required when entity type participates
multiple times in a relationship
-
12
CS 338: Computer Applications in Business: Databases (Fall 2014)
1992-2014 by Addison Wesley & Pearson Education, Inc., McGraw Hill, Cengage Learning Slides adapted and modified from Fundamentals of Database Systems (5/6) (Elmasri et al.), Database System Concepts (5/6) (Silberschatz et al.), Database Systems (Coronel et al.), Database Systems (4/5) (Connolly et al. ), Database Systems: Complete Book (Garcia-Molina et al.)
Relationship Constraints
Cardinality ratio Specifies maximum number of relationship instances in which each entity
can participate Types 1:1, 1:N, or M:N
Participation constraint
Specifies whether existence of entity depends on its being related to another entity
Types: total and partial Thus, minimum number of relationship instances in which entities can
participate: At least 1 for total participation At least 0 for partial
Diagrammatically, use a double line from relationship type to entity type
24
Relationship Constraints
Partial Participation If there is no participation constraint, it is possible that an entity will not
participate in a relationship set
Total Participation If there is a participation constraint, an entity must participate at least once
Presented by double line from entity set to relationship set
Alternative: Structural constraint Specify any min and max participation Generalization of cardinality ratio and participation constraint
E1 E2 R
E1 E2 R
25
-
13
CS 338: Computer Applications in Business: Databases (Fall 2014)
1992-2014 by Addison Wesley & Pearson Education, Inc., McGraw Hill, Cengage Learning Slides adapted and modified from Fundamentals of Database Systems (5/6) (Elmasri et al.), Database System Concepts (5/6) (Silberschatz et al.), Database Systems (Coronel et al.), Database Systems (4/5) (Connolly et al. ), Database Systems: Complete Book (Garcia-Molina et al.)
Relationship Attributes
Relationship types can also have attributes Property that depends on both/all participating entities Example: Percentage of control that department has on a project
Attributes of 1:1 or 1:N relationship types can be migrated to one of the participating entity types For a 1:N relationship type, relationship attribute can
be migrated only to entity type on N-side of relationship Attributes on M:N relationship types must be specified
as relationship attributes
26
Percent CONTROLS
Summary of Notation for ER Diagrams
Continued next page
-
14
CS 338: Computer Applications in Business: Databases (Fall 2014)
1992-2014 by Addison Wesley & Pearson Education, Inc., McGraw Hill, Cengage Learning Slides adapted and modified from Fundamentals of Database Systems (5/6) (Elmasri et al.), Database System Concepts (5/6) (Silberschatz et al.), Database Systems (Coronel et al.), Database Systems (4/5) (Connolly et al. ), Database Systems: Complete Book (Garcia-Molina et al.)
Summary of Notation for ER Diagrams
Appropriate ER Model Design
Choose names that convey meanings attached to different constructs in schema
Nouns give rise to entity type names
Verbs indicate names of relationship types
Entities that must participate in a relationship with another entity type and with cardinality constraint of 1 might be better modeled as weak entity