Академический Документы
Профессиональный Документы
Культура Документы
Entity
A person, place, object, event or concept in the user environment about which the organization wishes to maintain data Represented by a rectangle in E-R diagrams A collection of entities that share common properties or characteristics A named property or characteristic of an entity that is of interest to an organization
Entity Type
Attribute
Goal
Capture as much of the meaning of the data as possible If you know the rules of normalization, referential integrity, foreign keys, etc., this is good but not as important now. It is much more important to get the organizational data model correct, i.e. to understand the actual data requirements for the organization. A better design that is scalable and easier to maintain
Result
Entity A
Entity B
Entity C
Relationship
Classification of Constraints
1.
2.
3. 4.
Keys Single-value constraints Multi-valued constraints Mapping Cardinalities and Participation Constraints
Superkey is a set of one or more attributes that, taken collectively, for us to identify uniquely an item in the entity set. For example, customer-id is a superkey. Candidate key is a minimal superkey. For example, customer-name and customer-street is sufficient to distinguish among members of the customer entity set. Then {customer-name, customer-address } is a candidate key. Primary key denotes a candidate key that is chosen by the database designer as the principal means of identifying items within an entity set. the primary key should be chosen such that its attributes are never, or very rarely, changed. For example, Social-security numbers are guaranteed to never changed.
name
price
category
name
makes
Product
Company
stockprice
buys
employs
Person
address
name
ssn
category
What is a Relation ?
A mathematical definition:
A={1,2,3},
B={a,b,c,d},
2 3
b c
B=
Single/Multi-valued attributes
Single-valued attributes are attributes that only have a single value for a particular entity. Multi-valued attributes refers to items that are not singled-value and Null valued. For example, consider an employee entity set with the attribute phone-number. An employee may have zero, one, or several phone numbers; different employee may have different numbers of phones.
Express the number of items to which another item can be associated via a relationship set Are most useful in describing binary relationship sets. For a binary relationship set R between entity sets A and B, the mapping cardinality must be one of the following:
one-one:
1 2 3
a b c d
a b c d
many-one
1 2 3
many-many
1 2 3
a b c d
Participation Constraints
The participation of an entity set E in a relationship set R is said to be total, if every item in E participates in at least one relationship in R. If only some items in E participate in relationship R, the participation of entity set E in relationship R is said to be partial.
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.
since
dname
did
Manages
budget
Departments
Employees
Works_In
since
Attributes
An entity is represented by a set of attributes, that is descriptive properties possessed by all members of an entity set. Domain the set of permitted values for each attribute Attribute types: Simple and composite attributes. Single-valued and multi-valued attributes Example: multivalued attribute: phone_numbers Derived attributes Can be computed from other attributes Example: age, given date_of_birth
Compposite Attributes
Example: if we wish to track all access_dates to each account by each customer, we cannot assume a relationship for each access. We can use a multivalued attribute though
E-R Diagrams
Rectangles represent entity sets. Diamonds represent relationship sets. Lines link attributes to entity sets and entity sets to relationship sets. Ellipses represent attributes Double ellipses represent multivalued attributes. Dashed ellipses denote derived attributes. Underline indicates primary key attributes.
Roles
Entity sets of a relationship need not be distinct The labels manager and worker are called roles; they specify how employee entities interact via the works_for relationship set. Roles are indicated in E-R diagrams by labeling the lines that connectdiamonds to rectangles. Role labels are optional, and are used to clarify semantics of the relationship.
Cardinality Constraints
We express cardinality constraints by drawing either a directed line (), signifying one, or an undirected line (), signifying many, between the relationship set and the entity set. One-to-one relationship: A customer is associated with at most one loan via the relationship borrower A loan is associated with at most one customer via borrower.
One-To-Many Relationship
In the one-to-many relationship a loan is associated with at most one customer via borrower, a customer is associated with several (including 0) loans via borrower
Many-To-One Relationships
In a many-to-one relationship a loan is associated with several (including 0) customers via borrower, a customer is associated with at most one loan via borrower
Many-To-Many Relationship
A customer is associated with several (possibly 0) loans via borrower A loan is associated with several (possibly 0) customers via borrower
Movies
Stars-in
Stars
Name
Address
ISA Hierarchies
Software Products
Educational Products
Subclasses
name category
price
Product
isa
isa
Software Product
Educational Product
platforms
Age Group
Understanding Subclasses
Product
SoftwareProduct
field1 field2
field1 field2
field4 field5
Subclasses to Relations
Product
Name Gizmo Price 99 49 39 Categor y gadget photo gadget platform s unix Age Group todler retired
name
price
category
Camera Toy
Product
Sw.Product
isa
Name
Gizmo
isa
Ed.Product
Name
Gizmo Toy
Example-ISA
address birthday Movie Person id
name
ISA
picture
Actor
Director
For actors and directors, we want to store their name, a unique identification number, address and birthday. For actors, we also want to store a photograph For films, we want to store the title, year of production and type (thriller, comedy, etc.) We want to know who directed and who acted in each film. Every film has one director. We store the salary of each actor for each film
Requirements (2)
An actor can receive an award for his part in a film. We store information about who got which award for which film, along with the name of the award and year. We also store the name and telephone number of the organization who gave the award. Two different organizations can give an award with the same name. A single organization does not give more than one award with a particular name per year.
id
phone number
name
Organization
ISA
picture salary
Actor Acted In
Director
Directed
year
Weak entity sets are entity sets that are not uniquely identified by their attributes A weak entity set has an "identifying relationship" with an entity set that is the "identifying owner" of the weak entity set
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.
Employees
Policy
Dependents
Example
name
phone number
Organization
Example
Suppose that you were storing information about books. Should books be modeled as a weak entity set or a regular entity set?
title
Borrowed
Copy condition
copy number
Specialization
It is the process of defining a set of subclasses of a superclass. Top-down design process; we designate subgroupings within an entity set that are distinctive from other entities in the set. The set of subclasses based upon some distinguishing characteristics of entities in the superclass. Example:{SECRETARY,ENGINEER, DOCTOR} is a specialization of Employee based on Job type. Attribute of Sub class are called Specific Attributes.
Specialization Example
Aggregation
A bottom-up design process combine a number of entity sets that share the same features into a higher-level entity set. Several classes with common features are generalized into a superclass; oroginal classes become its subclasses. Example:CAR,TRUCK generalized into Vehicle. Specialization and generalization are simple inversions of each other; they are represented in an E-R diagram in the same way. The terms specialization and generalization are used interchangeably.
Aggregation Example
name ssn Employees lot
Monitors
until
since did
Sponsors
EXAMPLE
Use the following business rules to write all appropriate connectivities in the E-R diagram: a. A department employs many employees, but each employee is employed by one department. b. Some employees, known as "rovers," are not assigned to any department. c. A division operates many departments, but each department is operated by one division d. An employee may be assigned to many projects, and a project may have many employees assigned to it. e. A project must have at least one employee assigned to it. f. One of the employees manages each department, and each department is managed by only one employee. g. One of the employees runs each division, and each division is run by one employee.
DIVISION
operates
DEPARTMENT
employs
manages
runs
EMPLOYEE
is assigned to
PROJECT
EXAMPLE
Given the following summary of business rules for the ROBCOR catering service, draw the ERD. Make sure to include all appropriate entities, relationships, connectivities, and cardinalities.
Each dinner is based on a single entree, but each entree can be served at many dinners. A guest can attend many dinners, and each dinner can be attended by many guests. Each dinner invitation can be mailed to many guests, and each guest can receive many invitations.
M
ATTENDANCE
M (1,1) M (1,1)
(1,1)