FDBMS_Unit-2(a)
FDBMS_Unit-2(a)
2. Constraints
4. Entity-Relationship Diagrams
The function that an entity plays in a relationship is called that entity’s role.
A relationship may also have attributes called descriptive attributes.
The same entity set participates in a relationship set more than once, in
different roles is called a recursive relationship set,
Relationship Set advisor
Relationship Sets (Cont.)
An attribute can also be associated with a relationship set.
For instance, the advisor relationship set between entity sets
instructor and student may have the attribute date which tracks when
the student started being associated with the advisor
Degree of a Relationship Set
Binary relationship
involve two entity sets (or degree two).
most relationship sets in a database system are binary.
Attribute types:
Simple ( and composite (Name, Address) attributes.
Single-valued (Student Id) and multivalued (Phone No) attributes
Example: multivalued attribute: {Dependent_name}
Derived attributes
Can be computed from other attributes
Example: age, given date_of_birth (base/stored attribute) &
students_advised based on count
An attribute takes a null value when an entity does not have a value for it. It
may indicate “not applicable”— that is, that the value does not exist for the
entity.
a. Mapping Cardinalities
b. Participation Constraints
c. Keys
a. Mapping Cardinality Constraints
Express the to which another entity can be associated
via a relationship set.
Most useful in describing binary relationship sets.
For a binary relationship set the mapping cardinality must be one of the
following types:
One to one -An entity in A is associated with at most one entity in B,
and an entity in B is associated with at most one entity in A.
One to many - An entity in A is associated with any number (zero or
more) of entities in B. An entity in B, however, can be associated with
at most one entity in A.
Many to one - An entity in A is associated with at most one entity in
B. An entity in B, however, can be associated with any number (zero
or more) of entities in A.
Many to many- An entity in A is associated with any number (zero or
more) of entities in B, and an entity in B is associated with any
number (zero or more) of entities in A.
Mapping Cardinalities
One-to-one One-to-many
Note: Some elements in A and B may not be mapped to any elements in
the other set.
Mapping Cardinalities
Many-to-one Many-to-many
Note: Some elements in A and B may not be mapped to any
elements in the other set
Examples on cardinalities
consider the advisor relationship set.
If, in a particular university, a student can be advised by only one instructor,
and , then the relationship set from
instructor to student is one-to-many.
An instructor need not advise any students. Hence, it is possible that only
some of the instructor entities are related to the student entity set through
the advisor relationship, and the participation of instructor in the advisor
relationship set is therefore partial.
c. Keys
The values of the attribute values of an entity must be such
that they can uniquely identify the entity. In other words, no
two entities in an entity set are allowed to have exactly the
same value for all attributes.
The notion of weak entity set formalizes the above intuition. A weak entity set
is one whose existence is dependent on another entity, called its identifying
entity; instead of associating a primary key with a weak entity, we use the
identifying entity, along with extra attributes called discriminator to uniquely
identify a weak entity. An entity set that is not a weak entity set is termed a
strong entity set.
Weak Entity Sets (Cont.)
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.
Note that the relational schema we eventually create from the entity
set section does have the attribute course_id, for reasons that will
become clear later, even though we have dropped the attribute
course_id from the entity set section.
4. E-R Diagrams
Entity Sets
For each entity set and relationship set there is a unique schema that is
assigned the name of the corresponding entity set or relationship set.
Each value of the multivalued attribute maps to a separate tuple of the relation
on schema EM
For example, an instructor entity with primary key 22222 and phone
numbers 456-7890 and 123-4567 maps to two tuples:
(22222, 456-7890) and (22222, 123-4567)
iv. Representing Relationship Sets
A many-to-many relationship set is represented as a schema with
attributes for the primary keys of the two participating entity sets, and
any descriptive attributes of the relationship set.
Ex: Employee is the higher-level entity set and instructor and secretary
are lower-level entity sets.
ii. Generalization
Higher- and lower-level entity sets also may be designated by the terms
superclass and subclass, respectively.
The person entity set is the superclass of the employee and student
subclasses.
It proceeds from the recognition that a number of entity sets share some
common features. On the basis of their commonalities, generalization
synthesizes these entity sets into a single, higher-level entity set.
In our example:
The schema eval_for is:
eval_for (s_ID, project_id, i_ID, evaluation_id)
The schema proj_guide is redundant.
Representing Specialization via Schemas
Method 1:
Form a schema for the higher-level entity
Form a schema for each lower-level entity set, include primary
key of higher-level entity set and local attributes
schema attributes
person ID, name, street, city
student ID, tot_cred
employee ID, salary
Method 2:
Form a schema for each entity set with all local and inherited
attributes
schema attributes
person ID, name, street, city
student ID, name, street, city, tot_cred
employee ID, name, street, city, salary