Professional Documents
Culture Documents
Dtabase CH-3
Dtabase CH-3
1
5/28/2021
Entity Types, Entity Sets, Keys, and Value Sets Entity Types and Key Attributes (1)
Entity type Entities with the same basic attributes are grouped or typed into an
entity type.
Collection (or set) of entities that have the same attributes.
For example, the entity type EMPLOYEE and PROJECT.
Is the category to which the entity belongs
An attribute of an entity type for which each entity must have a unique
value is called a key attribute of the entity type.
For example, SSN of EMPLOYEE.
A key attribute may be composite.
VehicleTagNumber is a key of the CAR entity type with components
(Number, State).
Entity Set: Each entity type will have a collection of entities An entity type may have more than one key.
stored in the database
The CAR entity type may have two keys:
Is the current state of the entities of that type that are stored in
• VehicleIdentificationNumber (popularly called VIN)
the database. The complete data set of all entities is called
the entity set. In the above table, the entity set consists of • VehicleTagNumber (Number, State), aka license plate number.
all the records Each key is underlined
2
5/28/2021
box
Initial Design of Entity Types for the Initial Design of Entity Types:
COMPANY Database Schema EMPLOYEE, DEPARTMENT, PROJECT, DEPENDENT
Value sets (or domain of values) Some aspects in the requirements will be represented as
relationships
Specifies set of values that may be assigned to that attribute
for each individual entity ER model has three main concepts:
Entities (and their entity types and entity sets)
Attributes (simple, composite, multivalued)
Relationships (and their relationship types and
relationship sets)
3
5/28/2021
Types
In the refined design, some attributes from the initial entity
types are refined into relationships:
Manager of DEPARTMENT -> MANAGES
Works_on of EMPLOYEE -> WORKS_ON
Department of EMPLOYEE -> WORKS_FOR
etc
In general, more than one relationship type can exist
between the same participating entity types
MANAGES and WORKS_FOR are distinct relationship
types between EMPLOYEE and DEPARTMENT
Different meanings and different relationship instances.
4
5/28/2021
5
5/28/2021
The (min,max) notation for relationship constraints COMPANY ER Schema Diagram using (min, max)
notation
Read the min,max numbers next to the entity type and looking away from the entity type
6
5/28/2021
Relationship Degree..Cont.
Relationship Degree
Another important point about relationship is the range of instances that can be
Related entities require setting of LINKS from one part of the database to associated with a single instance from one entity in a single relationship.
another. The number of instances participating or associated with a single instance from
A relationship should be named by a word or phrase which explains its another entity in a relationship is called the CARDINALITY of the relationship.
function ONE-TO-ONE, e.g. Building - Location,
Role names are different from the names of entities forming the relationship:
ONE-TO-MANY, e.g. hospital - patient,
one entity may take on many roles, the same role may be played by different
MANY-TO-ONE, e.g. Employee - Department
entities.
MANY-TO-MANY, e.g. Author - Book.
An important point about a relationship is how many entities participate in it.
The number of entities participating in a relationship is called the DEGREE of
the relationship type.
UNARY/RECURSIVE RELATIONSHIP: Single entity
BINARY RELATIONSHIPS: Two entities associated
TERNARY RELATIONSHIP: Three entities associated
N-NARY RELATIONSHIP: arbitrary number of entity sets
7
5/28/2021
8
5/28/2021
9
5/28/2021
Disjoint, partial
Overlapping, total
Overlapping, partial
Note: Generalization usually is total because the superclass is derived
from the subclasses.
Specialization / Generalization Lattice Example (UNIVERSITY) Relational Database Design by ER- and EER-to-
Relational Mapping
Relational Database Design Using ER-to-Relational Mapping:
10
5/28/2021
11
5/28/2021
Generalization. (b) Generalizing CAR and TRUCK into the superclass VEHICLE.
Mapping EER Model Constructs to Relations (contd.)
Option 8C: Single relation with one type attribute
Create a single relation L with attributes Attrs(L) = {k,a1,…an} U
{attributes of S1} U…U {attributes of Sm} U {t} and PK(L) = k. The
attribute t is called a type (or discriminating) attribute that indicates
the subclass to which each tuple belongs
Subclasses are disjoint
Option 8D: Single relation with multiple type attributes
Options for mapping specialization or generalization.
Create a single relation schema L with attributes Attrs(L) = {k,a1,…an}
(b) Mapping the EER schema in the above Figure using option 8B.
U {attributes of S1} U…U {attributes of Sm} U {t1, t2,…,tm} and PK(L) = k.
Each ti, 1 < I < m, is a Boolean type attribute indicating whether a tuple
belongs to the subclass Si.
• Subclasses are overlapping
• Will also work for a disjoint specialization
EER diagram notation for an attribute-defined specialization on JobType. EER diagram notation for an overlapping (non-disjoint) specialization.
12
5/28/2021
FIGURE: Mapping the EER specialization lattice in Figure 4.6 using multiple options. The Relational Data Model and
Relational Database, Constraints
The model was first proposed by Dr. E.F. Codd of IBM Research
in 1970
13
5/28/2021
14
5/28/2021
Key Constraints and Constraints on NULL Values Key Constraints and Constraints on NULL Values (cont’d.)
No two tuples can have the same combination of values for all their
attributes.
Superkey: No two distinct tuples in any state r of R can have the same
value for SK
Key: Superkey of R
Removing any attribute A from K leaves a set of attributes K that is not
a superkey of R any more
Key satisfies two properties:
Two distinct tuples in any state of relation cannot have identical values
for (all) attributes in key Relational Integrity
Domain Integrity: No value of the attribute should be beyond the allowable
Minimal superkey: Cannot remove any attributes and still have
limits
uniqueness constraint in above condition hold Entity Integrity: In a base relation, no attribute of a primary key can be null
Candidate key: Relation schema may have more than one key Referential Integrity: If a foreign key exists in a relation, either the foreign key
value must match a candidate key in its home relation or the foreign key value
Primary key of the relation: Designated among candidate keys must be null foreign key to primary key match-ups
Underline attribute Enterprise Integrity: Additional rules specified by the users or database
administrators of a database are incorporated
Other candidate keys are designated as unique keys
Other Types of Constraints (cont’d.) Update Operations, Transactions, and Dealing with Constraint
Functional dependency constraint Violations
Operations of the relational model can be categorized into retrievals and
Establishes a functional relationship among two sets of attributes X updates
and Y
Basic operations that change the states of relations in the database:
Value of X determines a unique value of Y Insert, Delete, Update (or Modify)
State constraints
Define the constraints that a valid state of the database must satisfy
Transition constraints
Define to deal with state changes in the database
15
5/28/2021
16
5/28/2021
17