Unit4-Relational Data Model Notes
Unit4-Relational Data Model Notes
The relational model is very simple and elegant; a database is a collection of one or more
relations, where each relation is a table with rows and columns. This simple tabular
representation enables even novice users to understand the contents of a database and it permits
the use of simple, high-level languages to query the data. The major advantages of the relational
model over the older data models are its simple data representation and the ease with which even
complex queries can be expressed. The relational model represents the database as a collection of
relations (or tables). Informally each relation resembles a table of values or, to some extent, a
“flat” file of records. One of the main advantages of relational model is that it is conceptually
simple and more important. It also frees the users from detail of storage and access methods.
STUDENT
Domain:
“The set of permitted values for each attribute is called domain” or “A domain is referred to in a
relation schema by the attribute name and has a set of associated values”. A domain D is a set
of atomic values. By Atomic we mean that each value in the domain is individual as far as the
relational model is concerned. “The data type describing the types of values that can appear in
1
each column is represented by a domain of possible values.” For example Set_phone_number
can be declared as of character strings. The data type for Employee_ages is an integer number
between 15 and 80. For academic_deaprtment_names, the data type is the set of all characters
strings that represent valid department names. A domain is thus given a name, data type, and
format.
Tuples / Records:
In relational model terminology all the rows are called tuples or records in the relation. Consider
a relation STUDENT. In this relation there are three rows, it means there three tuples or records
in this relation.
Relation Schema:
“The relation schema describes the column headers for the table or relation”. A relation
schema R denoted by R (A1, A2, A3…An), is made up of a relation name R and a list of attributes
A1, A2, A3… An. Each attribute Aj, is the name of role played by some domain D in the relation
schema R. D is called domain of Aj and is denoted by dom (Aj). A relation schema is used to
describe a relation R, and R is called the name of this relation.
Using the data type of each attribute, the definition is sometimes written as:
STUDENT (RollNo: string, Name: string, Address: string, Home_Phone: number, OfficePhone:
number, DateOfBirth: date, GPA: real)
Relation:
The main construct for representing data in the relational model is a relation. “A relation
consists of a relation schema and a relation instance. The relation instance is a table, and
the relation schema describes the column heads for the table”. A relation (or relation state) r
of the relation schema R (A1, A2, A3…An), is a set of n–tuples r = {t 1, t2, t3, . . . .tn}, which is
2
denoted by r (R). Each 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.
STUDENT
RollNo Name Address Home_Phone Office_Phone DateOfBirth GPA
10S19830 Ravi Dharwad 9898989898 0836-2233445 27-Jul-1988 8.9
10S19840 Praveen Hubli 8989898989 0836-3355265 12-Apr-1987 9.0
10S19845 Vinayak Dharwad 9988776655 NULL 15- Dec-1986 8.5
In the above relation all the column headers are the attributes and all rows are the tuples and
STUDENT is the name of relation and schema of this table is the relation schema. “A relation is
defined as a set of tuples”.
In the above relation,
Relation Name : STUDENT
Attributes : 7 attributes (7 columns)
Tuples : 3 tuples (3 rows)
Degree :7
Characteristics of Relations:
3
4. Interpretation (Meaning) of a Relation:
The relation schema can be interpreted as a declaration or as a type of assertion. For
example the schema of the STUDENT relation as given below asserts that a student
entity has RollNo, Name, Address, Home_Phone, Office_Phone, DateOfBirth, and GPA.
Each tuple in the relation can be interpreted as a fact or a particular instance of the
assertion. For example in the following figure first tuple asserts the fact that there is a
student whose name is Ravi, RollNo is 30, GPA is 8.9 and so on. An alternative
interpretation of a relation schema is as a predicate in this case the values in each tuple
are interpreted as values that satisfy the predicate.
STUDENT
RollNo Name Address Home_Phone Office_Phone DateOfBirth GPA
10S19830 Ravi Dharwad 9898989898 0836-2233445 27-Jul-1988 8.9
10S19840 Praveen Hubli 8989898989 0836-3355265 12-Apr-1987 9.0
10S19845 Vinayak Dharwad 9988776655 NULL 15- Dec-1986 8.5
Super key:
Super key is a subset of one or more attributes that allows us to identify uniquely a tuple in the
relation. For example in the above relation the RollNo attribute of the relation STUDENT is
sufficient to distinguish one student entity or a tuple from another. Each relation contains a
default Super key which is a set of all the attributes. In above relation STUDENT, RollNo is key
because no two student tuples can have the same value for RollNo, Any set of attributes that
includes RollNo is a Super key – for example, {RollNo, Name}, {RollNo, Name, Address},
{RollNo, Name, DateOfBirth}, and the set of all attributes { RollNo, Name, Address,
Home_Phone, Office_Phone, DateOfBirth, and GPA} is also a Super key, which is default Super
key for this relation.
In general, any Super Key formed from a single attribute is also a key.
Candidate key:
A minimal subset of fields that uniquely identifies tuples in a relation is called a candidate key
for the relation. It is also called a minimal Superkey for a relation. A relation may have several
candidate keys.
These Candidate keys are the candidates that can qualify to become a primary key.
Though each candidate key qualifies to become a primary key, only one can be chosen as a
primary key. The rules a candidate key requires to become primary key are the attribute value of
the key can never be NULL in any domain of the key; it must be unique and static.
4
Primary key
Primary key is a key or a key attribute in a relation which allows only unique values to be
accepted by a relation. It does not allow a relation to accept null values. Primary key is a key by
which all the tuples can be identified uniquely. It restricts the duplicate rows in a relation.
The basic point that differentiates primary key from candidate key is that there can be only one
primary for any relation in a schema. However, there can be multiple candidate keys for a single
relation.
Primary key describes the unique and most important attribute of a relation whereas, the
candidate keys provide the candidates among which one can be selected as a primary key.
Every primary key is a candidate key, but vice versa is not true.
Foreign key
A foreign key is a column or columns of data in one relational database table (i.e. child table)
that connects to the primary key data of another table (i.e. parent table). A foreign key is a key
used to link two tables together. This is sometimes also called as a referencing key. For example
there are two relations CUSTOMER and CONTACT which contain Customer details and
Contact details of Customer respectively. An attribute {CustID} which is present in both the
relation can be considered as a primary key in CUSTOMER relation and as a foreign key in
CONTACT relation.
Alternate key
A relation may contain more than one candidate key. If one candidate key has been chosen as a
primary key then another candidate key is called alternate key in that relation.
5
Composite key:
In certain tables a single attribute cannot be used to identify rows uniquely then a combination of
two or more attributes is used to as a primary key. Such keys are called composite keys.
Domain Constraint:
Domain constraint specifies that within each tuple of a relation, the value of each attribute must
be an atomic value. By atomic means it cannot be further divided into sub components.
Integrity Constraint:
Integrity constraints are such constraints which are specified on the database schema and are
expected to hold on every valid database state of that schema. In addition to domain, key, and
NOT NULL constraints, two other types of constraints are considered which are entity integrity
constraint and referential integrity constraint.
6
Operations on Relations:
There are three basic update operations on relations: insert, delete, and update (or modify). They
insert new data, delete old data, or modify existing data thus changing the state of the database.