UNIT5
UNIT5
– relation state r of the relation schema R(A1, A2, ..., An), also denoted by
r(R), is a set of n-tuples r={t1, t2, ..., tn}. Each n-tuple t is an ordered list
of n values t =<v1, v2, ..., vn>, where each value vi, 1 <= i <= n, is an
element of dom(Ai) or is a special NULL value. The ith value in tuple t,
which corresponds to the attribute Ai, is referred to as t[ Ai ] or t.Ai (or
t[ i ] if we use the positional notation).
– Relation state is also called relation extension.
RELATIONAL DATA MODEL
Example:
Consider the tuple t = <‘15-2314’, ’ Peter’, ‘CEN’, ‘BSIT’, NULL, 21> from the
STUDENT relation in Figure 5-1; we have t[ID_No] = <’15-2314’>, and t[Name,
College, Age] = <‘Peter’, ‘CEN’, 21>.
RELATIONAL DATA MODEL
Informal Terms Formal Terms
Table Relation
Column Attribute/Domain
Row Tuple
Values in tuple
-Each value in a tuple is considered atomic.
-Null Values-unknown/not applicable
RELATIONAL DATABASE SCHEMA
Attributes that represent different concepts may have the same name in different
relations.
The attribute name ‘Name’ for both ‘Pname’ of PROJECT and ‘Dname’ of DEPARTMENT would
have been used – in this case, we would have two attributes that share the same name but
represent different real world concepts—project names and department names.
Identical attribute names that pertains to the same real-world concept but is used
in different roles (meanings) in the same relation must be given distinct attribute
names.
The concept of Social Security number appears twice in the EMPLOYEE relation once in the role of
the employee’s SSN, and once in the role of the supervisor’s SSN. The attribute names ‘Ssn’ and
‘Super_ssn’ were used respectively because they appear in the same relation and in order to
distinguish their meaning.
RELATIONAL MODEL CONSTRAINTS
• Constraints are conditions that must hold on all valid relation states. These
can also be seen as restrictions on the actual values in a database state
and are usually derived from the rules in the miniworld that the database
represents.
Domain Constraint
Domain constraints specify that within each tuple, the value of each attribute
A must be an atomic value from the domain dom(A). This constraint ensures
that every value of a tuple must be from the domain of its attribute (or it
could be NULL, if allowed for that attribute).
Key Constraint
All tuples in a relation must be distinct such that no two tuples can have the
same combination of values for all their attributes. The value of a key
attribute can be used to identify uniquely each tuple in the relation.
A relation schema may have more than one key. In this case, each of the keys is called a
candidate key. The other candidate keys not chosen to be the primary key are designated
as unique keys or alternate keys, and are not underlined.
RELATIONAL MODEL CONSTRAINTS
CONSTRAINT ON NULL VALUES
This constraint on attributes specifies whether NULL values are or are not permitted.
For example, if every STUDENT tuple must have a valid, non-NULL value for the ‘Name’
attribute, then ‘Name’ of STUDENT is constrained to be NOT NULL.
• For each regular binary 1:N relationship type R, identify the relation S that
represents the participating entity type at the N-side of the relationship type.
• Include as foreign key in S the primary key of the relation T that represents the
other entity type participating in R.
• Include any simple attributes (or simple components of composite attributes) of the
1:N relationship type as attributes of S.
RULES OF TRANSFORMING ER MODEL
INTO RELATIONAL DATABASE MODEL
Step 5. Mapping of binary M:N relationship types.
• For each binary M:N relationship type R, create a new relation (a relationship
relation) S to represent R.
• Include as foreign key attributes in S the primary keys of the relations that represent
the participating entity types; their combination will form the primary key of S.
• Include any simple attributes of the M:N relationship type (or simple components of
composite attributes) as attributes of S.
RULES OF TRANSFORMING ER MODEL
INTO RELATIONAL DATABASE MODEL
Step 6: Mapping of multi-valued attributes.
• For each n-ary relationship type R, where n > 2, create a new relation S to represent
R.
• Include as foreign key attributes in S the primary keys of the relations that represent
the participating entity types.
• Include any simple attributes of the n-ary relationship type (or simple components
of composite attributes) as attributes of S.
• The primary key of S is usually a combination of all the foreign keys that reference
the relations representing the participating entity types.
• If the cardinality constraints on any of the entity types E participating in R is 1, then
the primary key of S should not include the foreign key attribute that references the
relation E’ corresponding to E.
SUMMARY OF RELATION
ERMODEL RELATIONAL MODEL
Entity type Entity relation
1:1 or 1:N relationship type Foreign key (or relationship
relation)
M:N relationship type Relationship relation and two
foreign keys
n-ary relationship type Relationship relation and n
foreign keys
Simple attribute Attribute
Composite attribute Set of simple component
attributes
Multivalued attribute Relation and foreign key
Value set Domain
Key attribute Primary (or secondary) key
TRANSFORMING EER TO RELATIONAL