CHAPTER 3
Relation Schema
A Relation Schema refers to the structure of a Table. It indicates the Name of the
Relation Schema and the Names its Attributes (represented by Columns in the
table). For example R (A1, A2, ……, An) represents a Relation Schema named “R”
having n columns, representing the Attributes A 1,A2, …. An.
Domain of an Attribute The Domain of an Attribute A i is the set of permitted
(legal) values, that can be assigned to Attribute A i. It is possible for more than
one Attributes to have the same Domain or to have overlapping Domains.
- One value that is member of all domains is null, which implies that the
value is either unknown or non-existent; for example suppose an entity has
attribute telephone-number. It may have null value if an entity does not have a
telephone number or if the entity has telephone number, but number is not
known.
Degree of a Relation Schema
Let r(R) = {t1, t2 , ……, tm} where t1, t2 , ……, tm are the tuples in the relation.
The n-values in a tuple will represent an entity or a relationship. Thus, all the n
values in the tuple will be related to each other. That is why the resulting
database is called a “relational database”.
P S Gill
2
Note that a tuple is an Ordered List (not a Set) of n values. That is why the
order of the values in the tuple matters. A value V i (1 < I < n) in the tuple t will be
from the Domain of attribute Ai.
i.e. vi Î Domain (Ai)
A Relation can also be defined as a subset of the Cartesian Product of all the
Domains of its Attributes.
i.e. r (R) Í Domain (A1) x Domain (A2) X …… X Domain (An)
There can be more than one Relations (Tables) defined on the same Schema,
For example r1(R) and r2(R) are two independent relations defined on the same
Schema R. Both will have same Degree but may have different cardinalities.
The Cardinality of a relation will vary from moment to moment; but degree will
change very rarely.
Some Notations
Since a relation is defined as a set of tuples, the notation t Î r implies that tuple t
is in relation r
P S Gill
3
The Super Key of a Relation Schema R refers to the set of attributes K (K Í R),
which when taken collectively, will uniquely identify each tuple in a relation r(R).
The superset of a super-key will also be a super-key. Thus, a super-key may
have some extraneous attributes, without which the balance set still remains a
super-key. Such extraneous attributes, which need not be there in a super-key,
can be eliminated from the key.
In the above schemas, the relation schema “STUDENT” has the following
Candidate Keys:-
{Univ_Roll_No}
{Class_Roll_No, Year, Branch, Section}
{S_Name, DOB, Father_Name, Address} Assuming that twins will not
have same name
And Relation Schema “SUBJECT” has {Sub_Code} as its Candidate Key and
Relation Schema “RESULT” has {Roll_No, Sub_Code} as its candidate key.
P S Gill
4
Since the other two relation schemas have only one candidate key each,
the same will be designated as their respective Primary Keys.
Composite Key A Key, that includes more than one attributes, is called a
Composite Key.
Foreign Key A relation schema R may include among its attributes some
primary key of another schema S. This is called a Foreign Key in schema R.
The following three types of Integrity Constraints are applicable to all Relational
Databases:-
P S Gill
5
For each attribute, the permitted domain is specified in the schema definition;
for example the domain of “Year” is the set of Integers.
Suppose a relation r(R) with Key {A,B} has the following state:-
r(R)
A B C
P S Gill
6
A1 b1 c3
A2 b1 c1
A3 b2 c5
A1 b2 c7
A3 b2 c1
This relation state is invalid, since there are two tuples with value of {A,B}
equaling {a3, b2}. One of these two tuples must be deleted, only then it will be a
valid relation.
Let r(R) and s(S) be two relations and let a (aÍs) be a Foreign Key
(FK) in S referencing Primary Key “K” of R. The relation s(S) would be
legal (valid) only if for each tuple t s Î s, there exists a tuple tr Î r such
that tr [K] = ts [a]. A tuple ts Î s that does not satisfy this condition will
be called a “Dangling Tuple”, in the sense, that such tuples do not
have necessary support from relation r. Such Dangling Tuples are
invalid; and DBMS has to ensure that such tuples do not exist in the
database.
P S Gill
7
subject
Sub_Code Title
TCS-401 Comp Org
TCS-402 DBMS
TCS-301 Data Structure
result
Roll_No Sub_Code Semester Marks
0209130010 TCS-301 3 66
0209130010 TCS-401 4 57
0209130010 TCS-403 4 78
1. Strong Entity Set. The Primary key of the entity set forms the primary
key of the relation.
2. Weak Entity Set. Primary key of the relation comprises the union of the
primary key of the strong entity set on which the weak entity set is existence-
dependent and the discriminator of the weak entity set.
3. Relationship Set. The union of the primary keys of the related entity
sets becomes a super key of the relation. If the relationship is many to many,
then this super key is also the primary key of the relation. If the relationship is
many-to-one, then primary key of the “many-side” entity set is the primary key of
the relation. If the relationship is one-to-one, then primary key of any of the
related entity sets can be the primary key of the relation.
P S Gill
8
“Many-Side” Entity Set. For example, the table for ACCOUNT also contains the
key of Entity Set BRANCH.
For a one-to-one relationship set, the relationship table can be combined with the
table of any of the participating entity sets.
Entity Sets:-
Relationship Sets:-
P S Gill
9
SUBJECT STUDENT
RESULT
SUB-
OFFERED
Dept_Nam
e HOD
Fac_Code
Fac_Name
FACULTY DEPT
FAC-DEPT
Relational Database:-
P S Gill
10
Fac_Code
Semester S_Addr
Marks
Dept_Name HOD
Fac_Code
P S Gill
11
Exercises
P S Gill
12
P S Gill