DBMS 5
DBMS 5
INTRODUCTION:
• In relational data model, the data and relationships are represented by collection
of inter-related tables.
• Each table is a group of columns and rows, where column represents attributes of
an entity and row represents records.
• In relational data model,
✓ a row is called as tuple
✓ a column header is called an attribute
✓ the table is called a relation
Relation:
• The relational model for database management is an approach to logically
represent and manage the data stored in a database.
• In this model, the data is organized into a collection of two-dimensional inter-
related tables, also known as relations.
• Each relation is a collection of columns and rows, where the column represents
the attributes of an entity and the rows (or tuples) represent the records.
BHAVYA C 1
ST FRANCIS COLLEGE – DEPT OF CSA DBMS – CHAP 5
Relational Schema:
• It is the logical blueprint of the relation i.e., it describes the design and the
structure of the relation. It contains the table name, its attributes, and their types:
• TABLE_NAME (ATTRIBUTE_1 TYPE_1, ATTRIBUTE_2 TYPE_2, ...)
• For our student relation example, the relational schema will be:
• STUDENT (ROLL_NUMBER INTEGER, NAME VARCHAR (20), CGPA FLOAT)
BHAVYA C 2
ST FRANCIS COLLEGE – DEPT OF CSA DBMS – CHAP 5
CHARACTERISTICS OF A RELATION:
1. Ordering of tuples in a relation: A relation is defined as a set of tuples.
Mathematically, elements, of a set have no order among them; hence, tuples in a
relation do not have any particular order. In other words, a relation is not a
sensitive to the ordering of tuples.
3. Values and NULLs in the tuples: Each value in a tuple is an atomic value. A special
null value is used to represent values that are unknown or inapplicable to certain
tuples.
CONSTRAINTS ON RELATIONS:
• A property assigned to a table column that prevents certain types of invalid data
values from being placed in the column.
CATEGORIES OF CONSTRAINTS:
1. Inherent model-based constraints:
constraints that are inherent in the definition/assumptions of a particular data
model hold in every database having that data model as its underpinning.
Example: In the relational model, no two tuples in a relation can be duplicates.
BHAVYA C 3
ST FRANCIS COLLEGE – DEPT OF CSA DBMS – CHAP 5
BHAVYA C 4
ST FRANCIS COLLEGE – DEPT OF CSA DBMS – CHAP 5
DOMAIN CONSTRAINT:
• Domain constraint defines the domain or set of values for an attribute.
• It specifies that the value taken by the attribute must be the atomic value
from its domain.
• Example- Consider the following Student table-
Here, value ‘A’ is not allowed since only integer values can be taken by the age
attribute.
This relation satisfies the tuple uniqueness constraint since here all the tuples are
unique.
BHAVYA C 5
ST FRANCIS COLLEGE – DEPT OF CSA DBMS – CHAP 5
This relation does not satisfy the tuple uniqueness constraint since here all the
tuples are not unique.
KEY CONSTRAINT:
Key constraint specifies that in any relation:
✓ All the values of primary key must be unique.
✓ The value of primary key must not be null.
This relation does not satisfy the key constraint as here all the values of primary
key are not unique.
BHAVYA C 6
ST FRANCIS COLLEGE – DEPT OF CSA DBMS – CHAP 5
This relation does not satisfy the entity integrity constraint as here the primary key
contains a NULL value.
BHAVYA C 7
ST FRANCIS COLLEGE – DEPT OF CSA DBMS – CHAP 5
• Here, The relation ‘Student’ does not satisfy the referential integrity
constraint.
• This is because in relation ‘Department’, no value of primary key specifies
department no. 14.
• Thus, referential integrity constraint is violated.
BHAVYA C 8
ST FRANCIS COLLEGE – DEPT OF CSA DBMS – CHAP 5
RELATIONAL ALGEBRA:
• The relational algebra is a procedural query language.
• It consists of a set of operations that take one or two relations as input and produce
a new relation as their result.
BHAVYA C 9
ST FRANCIS COLLEGE – DEPT OF CSA DBMS – CHAP 5
• Example:
2. Project operator:
• Project operation is done by Projection Operator which is represented by "pi"(∏).
• It is used to retrieve certain attributes(columns) from the table. It is also known
as vertical partitioning as it separates the table vertically.
• It is also a unary operator.
• syntax : ∏ a(r)
Where ∏ is used to represent PROJECTION
r is used to represent RELATION
a is the attribute list
• Suppose we want the names of all students from STUDENT Relation.
∏ NAME(STUDENT)
BHAVYA C 10
ST FRANCIS COLLEGE – DEPT OF CSA DBMS – CHAP 5
BHAVYA C 11