Modeling Your Data - PowerPoint PPT Presentation

About This Presentation
Title:

Modeling Your Data

Description:

Title: The Entity-Relationship Model Subject: Database Management Systems Author: Raghu Ramakrishnan and Johannes Gehrke Keywords: Chapter 2 Last modified by – PowerPoint PPT presentation

Number of Views:208
Avg rating:3.0/5.0
Slides: 31
Provided by: RaghuRa55
Learn more at: http://web.cs.wpi.edu
Category:

less

Transcript and Presenter's Notes

Title: Modeling Your Data


1
Modeling Your Data
  • Chapter 2

2
Overview of Database Design
  • Conceptual design
  • 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?

3
Overview of Database Design
  • ER Model is used at this stage.
  • A database schema in the ER Model can be
    represented pictorially (ER diagrams).
  • Can map an ER diagram into a relational schema.

4
ER Model Basics
  • Entity Real-world object distinguishable from
    other objects. An entity is described (in DB)
    using a set of attributes.
  • Entity Set A collection of similar entities.
    E.g., all employees.
  • All entities in entity set have same set of
    attributes.
  • Each entity set has a key.
  • Each attribute has a domain.

5
ER Model Basics (Contd.)
  • Relationship Association among two or more
    entities.
  • E.g., Attishoo works in Pharmacy depart.
  • 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 from
    E1, ..., en from En
  • Same entity set could participate in different
    relationship sets, or in different roles in
    same set.

6
ER Model Basics (Contd.)
since
name
dname
ssn
lot
budget
did
Works_In
Departments
Employees
  • Relationship Association among two or more
    entities.

7
ER Model Basics (Contd.)
name
ssn
lot
Employees
super-visor
subor-dinate
Reports_To
  • Relationship
  • Same entity set could participate in different
    relationship sets, or in different roles in the
    same set.

8
Key Constraints
1-to-1
1-to Many
Many-to-1
Many-to-Many
9
Which key constraint ?
since
name
dname
ssn
lot
budget
did
Works_In
Departments
Employees
10
Key constraints
since
name
dname
budget
ssn
lot
did
Works_In
Departments
Employees
  • Consider Works_In
  • An employee can work in many departments and
  • a dept can have many employees.

11
Which key constraint ?
since
name
dname
ssn
lot
budget
did
Works_In
Departments
Employees
1-to-1
1-to Many
Many-to-1
Many-to-Many
12
Which Key Constraint Case ??
  • Consider Manager Relation-ship?

budget
did
Departments
13
Which Key Constraint Case ??
  • Consider Manager Relation-ship?
  • Each dept has at most one manager.

budget
did
Departments
1-to-1
1-to Many
Many-to-1
Many-to-Many
14
Key Constraint 1 - to - many
  • Each dept has at most one manager, according to
    the key constraint on Manages.

budget
did
Departments
budget
did
0n
01
Departments
15
Key Constraints all four cases ?
  • In contrast, each dept has at most one manager,
    according to the key constraint on Manages.

budget
did
Departments
1-to-1
1-to Many
Many-to-1
Many-to-Many
16
Key Constraints
budget
did
  • 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.

Departments
1-to-1
1-to Many
Many-to-1
Many-to-Many
17
Participation Constraints
  • Must every department have a manager?

since
since
name
name
dname
dname
ssn
lot
budget
did
budget
did
?
?
Departments
Employees
Manages
18
Participation Constraints
  • If every department has a manager,
  • then this is a participation constraint
  • the participation of Departments in Manages
    is said to be total (vs. partial).

since
since
name
name
dname
dname
budget
did
budget
did
ssn
lot
?
?
Departments
Employees
Manages
19
Participation Constraints
  • Or, put differently,
  • every did value in Departments table must
    appear in a row of the Manages table (with a
    non-null ssn value!)

since
since
name
name
dname
dname
budget
did
budget
did
ssn
lot
?
?
Departments
Employees
Manages
20
Participation Constraints
  • Every department must have a manager!

since
since
name
dname
name
dname
ssn
lot
budget
did
budget
did
Departments
Employees
Manages
21
Participation Constraints ?
since
name
dname
budget
ssn
lot
did
Works_In
Departments
Employees
22
Participation Constraints !
  • every department have a manager
  • every employe works in at least one dept.
  • every dept has at least one employee

since
since
name
dname
name
dname
ssn
lot
budget
did
budget
did
Departments
Employees
Manages
Works_In
since
23
Weak Entities
  • A weak entity can be identified uniquely only by
    considering the primary key of another (owner)
    entity.

name
cost
pname
age
ssn
lot
Dependents
Policy
Employees
24
Weak Entities
  • weak entity identified uniquely only by
    considering 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.

name
cost
pname
age
ssn
lot
Dependents
Policy
Employees
25
ISA (is a) Hierarchies
1. As in C, or other PLs, attributes are
inherited. 2. If we declare A ISA B, every A
entity is also considered to be a B entity.
name
ssn
lot
Employees
hourly_wages
hours_worked
ISA
contractid
Contract_Emps
Hourly_Emps
26
ISA (is a) Hierarchies
name
ssn
lot
Implicit Relationship Between Super- And
Subentity? 1-1 ?
Employees
hourly_wages
hours_worked
ISA
contractid
Contract_Emps
Hourly_Emps
  • Reasons for using ISA
  • To add descriptive attributes specific to a
    subclass.
  • To identify entities that participate in a
    relationship.

27
ISA (is a) Hierarchies
name
ssn
lot
Employees
hours_worked
hourly_wages
ISA
contractid
Contract_Emps
Hourly_Emps
  • Overlap constraints Can Joe be Hourly_Emps as
    well as 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)

28
ISA (is a) Hierarchies
name
ssn
lot
Employees
hours_worked
hourly_wages
  • As in C, or other PLs, attributes are
    inherited.
  • If we declare A ISA B, every A entity is also
    considered to be a B entity.

ISA
contractid
Contract_Emps
Hourly_Emps
  • 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)
  • Reasons for using ISA
  • To add descriptive attributes specific to a
    subclass.
  • To identify entitities that participate in a
    relationship.

29
Aggregation
name
ssn
lot
Monitors
until
since
started_on
dname
pid
pbudget
did
budget
Sponsors
Departments
Projects
  • Used when we have to model a relationship
    involving entity sets and a relationship set.

30
Aggregation
name
lot
ssn
Monitors
until
since
started_on
dname
pid
pbudget
did
budget
Sponsors
Departments
Projects
Aggregation allows us to treat a relationship set
as an entity set for purposes of participation
in (other) relationships
31
Aggregation
name
lot
ssn
Monitors
until
since
started_on
dname
pid
pbudget
did
budget
Sponsors
Departments
Projects
  • Aggregation vs. ternary relationship
  • Monitors is a distinct relationship, with a
    descriptive attribute.
  • Also, can say that each sponsorship is
    monitored by at most one employee.

32
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.
  • Basic constructs entities, relationships, and
    attributes (of entities and relationships).
  • Some additional constructs weak entities, ISA
    hierarchies, and aggregation.
  • Note There are many variations on ER model.

33
Summary of ER (Contd.)
  • Several kinds of integrity constraints can be
    expressed in ER model
  • key constraints,
  • participation constraints, and
  • overlap/covering constraints for ISA hierarchies.
  • Some foreign key constraints also implicit in
    definition of a relationship set.
  • Some constraints (notably, functional
    dependencies) cannot be expressed in the ER
    model.
  • Constraints play an important role in determining
    the best database design for an enterprise.
Write a Comment
User Comments (0)
About PowerShow.com