cmpt 258 database systems
DESCRIPTION
CMPT 258 Database Systems. The Entity-Relationship Model ( Chapter 2). Overview of Database Design. Conceptual design : ( ER Model is used at this stage.) What are the entities and relationships in the enterprise? - PowerPoint PPT PresentationTRANSCRIPT
CMPT 258 Database SystemsThe Entity-Relationship Model(Chapter 2)
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 that hold?
– A database ‘schema’ in the ER Model can be represented pictorially (ER diagrams).
– Can map an ER diagram into a relational schema.
ER Model Basics• Entity-Relationship (ER) data model – A database can be modeled as a collection of
entities and relationship among entities– Widely used to develop an initial database
design
• Entity: • Real-world object distinguishable from other
objects. – An entity is described (in DB) using a set of
attributes.
– Degree of an entity: number of attributes
Employees
ssnname
lot
ER Model Basics (cont.)• Entity Set: A collection of similar entities.
• E.g., all employees. – All entities in an entity set have the same set of
attributes.– Each entity set has a key.
• Key: a minimal set of attributes whose values uniquely identify an entity in the set
Employees
ssnname
lot
ER Model Basics (cont.)– Each entity set has a key.
• Key (Candidate Key): a minimal set of attributes whose values uniquely identify an entity in the set
• There could be more than one candidate keys; if so, we designate one of them as the primary key.
Employees
ssnname
lot
ER Model Basics (cont.)– Each attribute has a domain.
• A domain defines the possible values of each attributes• E.g., attribute name might be the set of 20-character string• E.g., attribute rating may have its domain of integers 1
through 10.
•Specifying a domain ▫Data type specified for each domain
Domain Constraints•Typically include:
▫Numeric data types for integers and real numbers
▫Characters▫Booleans▫Fixed-length strings▫Variable-length strings▫Date, time, timestamp▫Money▫Other special data types
ER Model Basics (cont.)• Relationship: Association among two or more
entities. – E.g., James works in Pharmacy department.– Descriptive attribute, since–Used to record information about the
relationship, rather than about any one of the participating entities.
did
dname
budget
Departments
lot
sincename
Works_InEmployees
ssn
ER Model Basics (cont.)• Relationship: Association among two or more
entities. – A relationship must be uniquely identified
by the participating entities, without reference to the descriptive attributes.
did
dname
budget
Departments
lot
sincename
Works_InEmployees
ssn
ER Model Basics (cont.)
•Relationship Set: Collection of similar relationships.
•Same entity set could participate in different relationship sets
lot
name dnamebudgetdid
sincename dname
budgetdid
since
Manages
since
DepartmentsEmployees
ssn
Works_In
ER Model Basics (cont.)
•Instance of a relationship set is a set of relationships.
Ternary Relationship
•Suppose that each department has offices in several locations and we want to record the locations at which each employee works.
ER Model Basics (cont.)•A relationship might involve two entities
in the same entity set▫Reports_To (emp1, emp2)▫Two entities with different “roles” in same
set.▫role indicators▫Reports_To (subordinate_ssn, ▫supervisor_ssn)
subor-dinate
super-visor
Reports_To
lot
name
Employees
ssn
Key Constraints• Consider Works_In: An
employee can work in many departments; a dept can have many employees.▫1:1▫1:N▫N:1▫M:N
Many-to-Many1-to-1 1-to Many Many-to-1
did
dname
budget
Departments
lot
sincename
Works_InEmployees
ssn
M N
Key Constraints• In contrast, each dept has
at most one manager, according to the key constraint on Manages.
Many-to-Many1-to-1 1-to Many Many-to-1
dname
budgetdid
since
lot
name
ssn
ManagesEmployees Departments1 N
Key Constraints
• The constraint that each department has at most one manager is an example of a key constraint, and it implies that each Departments entity appear in at most one Manages relationship.
• Arrow states that given a Department entity, we can uniquely determine the manages relationship in which it appears.
Many-to-Many1-to-1 1-to Many Many-to-1
dname
budgetdid
since
lot
name
ssn
ManagesEmployees Departments
Key Constraints• Each department
has only one manager
• And each employee can manage only one department.
• Cardinality ratio
18
Many-to-Many1-to-1 1-to Many Many-to-1
dname
budgetdid
since
lot
name
ssn
ManagesEmployees Departments1 1
ExercisesEntity 1 Cardinality Ratio Entity 2
Student SocialSecurityCard
Student Teacher
ClassRoom Wall
Country CurrentPresident
Course TextBook
Item (that can be found in an order)
Order
Student Class
Class Instructor
Instructor Office
E-bay Auction item
E-bay bid
Participation Constraints•Does 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 Departments entity must appear in an instance of the Manages relationship.
lot
name dnamebudgetdid
sincename dname
budgetdid
since
Manages
since
DepartmentsEmployees
ssn
Works_In
Participation Constraints•Does 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 Departments entity must appear in an instance of the Manages relationship.
lot
name dnamebudgetdid
sincename dname
budgetdid
since
Manages
since
DepartmentsEmployees
ssn
Works_In
1
M N
N
• If the participation of an entity set in a relationship set is total, the two are connected by a thick line
lot
name dnamebudgetdid
sincename dname
budgetdid
since
Manages
since
DepartmentsEmployees
ssn
Works_In
Exercises
23
24
Weak Entities• Employees can purchase insurance to cover their
dependents.
lot
name
agepname
DependentsEmployees
ssn
Policy
cost
ssn
Weak Entities• Employees can purchase insurance to cover their
dependents.• Only dependents’ SSN is not needed• If an employee quits, any policy owned by the
employee is terminated and all relevant policy and dependent info will be deleted from the database.
lot
name
agepname
DependentsEmployees
ssn
Policy
cost
ssn
1 N
Weak Entities• Employees can purchase insurance to cover their
dependents.• Only dependents’ SSN is not needed• If an employee quits, any policy owned by the
employee is terminated and all relevant policy and dependent info will be deleted from the database.
lot
name
agepname
DependentsEmployees
ssn
Policy
cost
N1
Weak Entities• A weak entity can be identified uniquely only by
considering the primary key of another (owner) entity.▫Partial key: the set of attributes of a weak
entity set that uniquely identify a weak entity for a given owner entity
lot
name
agepname
DependentsEmployees
ssn
Policy
cost
1 N
Weak Entities• Owner entity set and weak entity set must
participate in a one-to-one or one-to-many relationship set (one owner, one or more weak entities).
• Weak entity set must have total participation in this identifying relationship set. ▫ identifying owner, strong entity
lot
name
agepname
DependentsEmployees
ssn
Policy
cost
Summary so far
•Entities and Entity Set (boxes)•Relationships and Relationship sets (diamonds)
▫binary▫ternary▫n-ary
•Key constraints (1:1,1:N, N:1, M:N, arrows on 1 side)
•Participation constraints (total and partial)•Weak entities - require strong entity for key•Next, a couple more advanced concepts…