0% found this document useful (0 votes)
24 views

Unit4-Relational Data Model Notes

The document discusses the relational data model and its key concepts. The relational model uses tables to store data and relationships. It defines concepts like relations, attributes, domains, tuples and keys. Relations are made up of tuples and have a relational schema defining their attributes. Keys like super keys and candidate keys uniquely identify tuples.

Uploaded by

108 Anirban
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views

Unit4-Relational Data Model Notes

The document discusses the relational data model and its key concepts. The relational model uses tables to store data and relationships. It defines concepts like relations, attributes, domains, tuples and keys. Relations are made up of tuples and have a relational schema defining their attributes. Keys like super keys and candidate keys uniquely identify tuples.

Uploaded by

108 Anirban
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Unit IV

The Relational Data Model

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.

Concept of Relational Model:


A relational model was proposed by Ted Codd of IBM Research in 1970. Basic concept in
relational model is that the relation can be viewed as a table which has the following properties
 It is column homogenous in other words in any given column of the table all items are of
same kind
 Each item is a simple character string or a number
 All rows of a table or relation are distinct
 The ordering of rows within a table is a immaterial
 The column of a table are assigned distinct name and ordering of these columns is
immaterial.

Domain, Attribute, Tuple, and Relations


Attributes:
In relational model terminology all the column headers are called attributes. Consider a table
STUDENT. In this table there are seven column headers, it means this table has seven attributes
RollNo, Name, Address, Home_Phone, Office_Phone, DateOfBirth, GPA.

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

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.

The domain of each attribute in STUDENT Relation is as follows:


RollNo : 08 alphanumeric characters
Name : Characters
Address : Alphanumeric characters
Home_Phone : 10 digit numbers
Office_Phone : 11 digit numbers
DateOfBirth : Date
GPA : (0…10) float

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.

“The degree of a relation is the number of attributes of its relation schema”.


An example of a relation schema for a relation degree seven, which describes university students,
is the following

STUDENT (RollNo, Name, Address, Home_Phone, Office_Phone, DateOfBirth, GPA)

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:

1. Ordering of Tuples in a Relation:


A relation is defined as a set of tuples. Tuples in a relation do not have any particular
order. Tuple ordering is not a part of relation definition, because a relation attempts to
represent facts at a logical or abstract level. For example tuples in the STUDENT relation
could be logically ordered by RollNo, Name, Address, Home_Phone, Office_Phone,
DateOfBirth, GPA or by some other attribute.

2. Ordering of Values within a Tuple:


According to the preceding definition of a relation, an n-tuple is an ordered list of n
values, so the ordering of values in tuple is important. However at a logical level, the
order of attributes and their values is not that important as long as the correspondence
between attributes and values is maintained.

3. Values and NULLs in the Tuples:


Each value in a tuple is an atomic value. It means it is not divisible into components
within the framework of the basic relational model. Hence, composite and multivalued
attributes are not allowed. This model is sometimes called the flat relational model.
An important concept is that of NULL values, which are used to represent the values of
attributes that may be unknown or may not apply to a tuple. A special value, called
NULL is used in these cases.

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

Different Types of Keys:


Key:
“A key is a subset of one or more fields that allows us to identify a set of attributes that is
sufficient to distinguish tuples from each other”. It is used to implement the concept of key
constraints in the relations.

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.

Relational Model Constraints:


The main types of constraints that can be expressed in the relational model are as
1. Domain constraint
2. Key constraints and constraints on NULL values
3. Integrity constraint
a. Entity integrity constraint
b. Referential integrity constraint

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.

Key Constraint and Constraints on NULL Values:


A relation is defined as a set of tuples. By definition all the elements of a set are distinct; hence,
all the tuples in a relation must also be distinct. This means that no two tuples can have the same
combination of values for all their attributes. A key constraint is a statement that a certain subset
of the fields of a relation is a unique identifier for a tuple.
Another constraint on attributes specifies whether NULL values are permitted or not. 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.

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.

a. Entity Integrity Constraint:


The entity constraint specifies that no primary key value can be null. This is because the
primary key value is used to identify individual tuples in a relation. Having null values
for the primary key implies that we cannot identify some tuples.
b. Referential Integrity Constraint:
The referential integrity constraint is specified between two relations and is used to
maintain the consistency among the tuples in two relations. The condition for a foreign
key specifies a referential integrity constraint between two relations. Informally, the
referential integrity constraint states that a tuple in one relation that refers to another
relation must refer to an existing tuple in that relation.

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.

The Insert Operation:


Insert is used to insert a new tuple or tuples in a relation. Insert operation can violate any of the
four types of constraints.
(1) Domain constraint can be violated if an attribute value is given that does not appear in the
corresponding domain.
(2) Key constraint can be violated if a key value in the new tuple already exists in another tuple
in the relation.
(3) Entity integrity can be violated if the primary key of the new tuple is NULL.
(4) Referential integrity can be violated if the value of any foreign key in referencing relation
(child relation) refers to a tuple that does not exist in the referenced relation (parent relation).

The Delete Operation:


Delete is used to delete the tuples. Delete operation can violate only referential integrity, if the
tuple being deleted is referenced by the foreign key from other tuples in the database. While
deleting a value from primary key column, make sure that the deleted attribute value is not
present in the referencing foreign key column. However, there is no constraint on deleting a
value from a foreign key column.

The Update Operation:


Update (or Modify) operation is used to change the values of one or more attributes in a tuple
(or tuples) of some relation. It is necessary to specify a condition on the attributes of the relation
to select the tuple (or tuples) to be modified.
Updating an attribute that is neither a primary key nor a foreign key usually causes no problems;
the DBMS need only check to confirm that the new value is of the correct data type and domain.
Modifying a primary key value is similar to deleting one tuple and inserting another in its place
because we use the primary key to identify tuples.

You might also like