Week-3 (Section-2 (Part-1 ER Modeling) )
Week-3 (Section-2 (Part-1 ER Modeling) )
2.4
Attributes
The set of allowed values for each attribute is called the domain of the
attribute
Attribute values are (normally) required to be atomic; that is, indivisible
The special value null is a member of every domain. Indicated that the
value is ―unknown‖
The null value causes complications in the definition of many operations
2.5
Relations are Unordered
2.6
Database Schema
2.7
Relational Integrity Constraints
2.8
Formal Definitions - Domain
2.9
Keys
Let K R
K is a superkey of R if values for K are sufficient to identify a unique tuple
of each possible relation r(R)
• Example: {ID} and {ID,name} are both superkeys of instructor.
Superkey K is a candidate key if K is minimal
Example: {ID} is a candidate key for Instructor
One of the candidate keys is selected to be the primary key.
• Which one?
Foreign key constraint: Value in one relation must appear in another
• Referencing relation
• Referenced relation
• Example: dept_name in instructor is a foreign key from instructor
referencing department
2.10
Entity Integrity
Entity Integrity:
• The primary key attributes PK of each relation
schema R in S cannot have null values in any
tuple of r(R).
This is because primary key values are used to identify
the individual tuples.
t[PK] null for any tuple t in r(R)
If PK has several attributes, null is not allowed in any of
these attributes
• Note: Other attributes of R may be constrained to
disallow null values, even though they are not
members of the primary key.
2.11
Referential Integrity
2.12
Referential Integrity
2.13
Referential Integrity (or foreign key)
Constraint
Statement of the constraint
• The value in the foreign key column (or columns) FK of the the
referencing relation R1 can be either:
(1) a value of an existing primary key value of a corresponding
primary key PK in the referenced relation R2, or
(2) a null.
In case (2), the FK in R1 should not be a part of its own primary key.
2.14
Displaying a relational database schema and
its constraints
Each relation schema can be displayed as a row of
attribute names
The name of the relation is written above the
attribute names
The primary key attribute (or attributes) will be
underlined
A foreign key (referential integrity) constraints is
displayed as a directed arc (arrow) from the foreign
key attributes to the referenced table
• Can also point the the primary key of the referenced
relation for clarity
Next slide shows the COMPANY relational schema
diagram
2.15
Referential Integrity Constraints for COMPANY database
2.16
Schema Diagram for University Database
2.17
Other Types of Constraints
2.18
Design Phases
2.19
Design Phases (Cont.)
2.20
Design Alternatives
2.21
Design Approaches
2.22
Outline of the ER Model
2.23
Entity Sets
2.25
Representing Entity sets in ER Diagram
2.27
Relationship Sets
2.28
Relationship Sets (Cont.)
2.29
Representing Relationship Sets via ER Diagrams
2.30
Relationship Sets (Cont.)
student
2.31
Relationship Sets with Attributes
2.32
Roles
2.33
Degree of a Relationship Set
Binary relationship
• involve two entity sets (or degree two).
• most relationship sets in a database system are binary.
Relationships between more than two entity sets are rare. Most
relationships are binary. (More on this later.)
• Example: students work on research projects under the guidance of
an instructor.
• relationship proj_guide is a ternary relationship between instructor,
student, and project
2.34
Non-binary Relationship Sets
2.35
Complex Attributes
Attribute types:
• Simple and composite attributes.
• Single-valued and multivalued attributes
Example: multivalued attribute: phone_numbers
• Derived attributes
Can be computed from other attributes
Example: age, given date_of_birth
Domain – the set of permitted values for each attribute
2.36
Composite Attributes
component
attributes
street_number street_name apartment_number
2.37
Representing Complex Attributes in ER Diagram
2.38
Mapping Cardinality Constraints
2.39
Mapping Cardinalities
2.40
Mapping Cardinalities
2.41
Representing Cardinality Constraints in ER Diagram
2.42
One-to-Many Relationship
2.43
Many-to-One Relationships
2.44
Many-to-Many Relationship
2.45
Total and Partial Participation
Total participation (indicated by double line): every entity in the entity set
participates in at least one relationship in the relationship set
2.46
Notation for Expressing More Complex Constraints
2.47
Alternative (min, max) notation for
relationship structural constraints:
Specified on each participation of an entity type E in a
relationship type R
Specifies that each entity e in E participates in at least min and
at most max relationship instances in R
Default(no constraint): min=0, max=n (signifying no limit)
Must have minmax, min0, max 1
Derived from the knowledge of mini-world constraints
Examples:
• A department has exactly one manager and an employee
can manage at most one department.
Specify (0,1) for participation of EMPLOYEE in MANAGES
Specify (1,1) for participation of DEPARTMENT in MANAGES
• An employee can work for exactly one department but a
department can have any number of employees.
Specify (1,1) for participation of EMPLOYEE in WORKS_FOR
Specify (0,n) for participation of DEPARTMENT in
WORKS_FOR
2.48
The (min,max) notation for relationship
constraints
2.49
COMPANY ER Schema Diagram using
(min, max) notation
2.50
Primary Key
Primary keys provide a way to specify how entities and relations are
distinguished. We will consider:
• Entity sets
• Relationship sets.
• Weak entity sets
2.51
Primary key for Entity Sets
2.52
Primary Key for Relationship Sets
2.53
Choice of Primary key for Binary Relationship
2.54
Weak Entity Set
An entity set that is not a weak entity set is termed a strong entity set.
Every weak entity must be associated with an identifying entity; that is,
the weak entity set is said to be existence dependent on the identifying
entity set.
The identifying entity set is said to own the weak entity set that it
identifies.
The relationship associating the weak entity set with the identifying entity
set is called the identifying relationship.
2.56
Expressing Weak Entity Sets
2.57
E-R Diagram for a University Enterprise
2.58