DBMS 12
DBMS 12
After designing of database, i.e., ER diagram design then converting it into relational model
followed by normalization and indexing, now task is how to store, retrieve and modify data
in database.
Query Language: Languages in which user request some information from database.
Query language can be two types:
1. Procedural Query Language
2. Non-procedural Query Language
Relational Algebra-
Characteristics-
Following are the important characteristics of relational operators-
Relational algebra is one of the two formal query language associated with relational
model.
Like any other mathematical system is defined a number of operators and use relations
(tables) as operands.
Every operator in relational algebra takes one or two relations as an input argument and
generates a single relation as a result without a name.
The table produced by a relational operator has all the properties of a relational model.
Relational algebra does not consider duplicity as it is based on set theory.
In each query we describe a step by step procedure for computing the desired result. So
it is a procedural query language.
No use of English keywords.
Selection Operator-
Selection Operator (σ) is a unary operator in relational algebra so it can take only one
table at a time that performs a selection operation.
It is a fundamental operator.
It selects those rows or tuples from the relation that satisfies the selection condition.
It has same function as of where clause in SQL.
Minimum number of tuples selected is zero.
Maximum number of tuples selected is all of the tuples in a relation.
Syntax-
σ<selection_condition/predicate>(R)
σBrnach=CST(Student)
More examples -
Important Points-
Point-01:
We may use logical operators like ∧ Logical AND , ∨ Logical OR , ! [Logical NOT] and
relational operators like = , ≠ , > , < , <= , >= with the selection condition.
Point-02:
Selection operator only selects the required tuples according to the selection
condition.
It does not display the selected tuples.
To display the selected tuples, projection operator is used.
Point-03:
Selection operator always selects the entire tuple. It cannot select a section or part of
a tuple.
Point-04:
Point-05:
Degree of the relation from a selection operation is same as degree of the input
relation.
Point-06:
The number of rows returned by a selection operation is obviously less than or equal
to the number of rows in the original table.
Thus,
Minimum Cardinality = 0
Maximum Cardinality = |R|
Projection Operator-
Projection Operator (π) is a unary operator in relational algebra which take one table
at a time and performs a projection operation.
It is also fundamental operator.
It displays the columns of a relation or table based on the specified attributes.
It works as of select clause in SQL.
Syntax-
π<attribute list/column_name>(R)
Example-
Consider the following Student relation-
Name Age
Ashish 19
Rahul 20
Naina 20
Sameer 21
ID Name
100 Ashish
200 Rahul
300 Naina
400 Sameer
Important Points-
Point-01:
The degree of output relation (number of columns present) is equal to the number of
attributes mentioned in the attribute list.
Point-02:
Projection operator automatically removes all the duplicates while projecting the
output relation.
So, cardinality of the original relation and output relation may or may not be same.
If there are no duplicates in the original relation, then the cardinality will remain
same otherwise it will surely reduce.
Point-03:
If attribute list is a super key on relation R, then we will always get the same number
of tuples in the output relation.
This is because then there will be no duplicates to filter.
Point-04:
Projection operator does not obey commutative property i.e.
Point-07:
There is only one difference between projection operator of relational algebra and
SELECT operation of SQL.
Projection operator does not allow duplicates while SELECT operation allows
duplicates.
To avoid duplicates in SQL, we use “distinct” keyword and write SELECT distinct.