Relational Algebra in Dbms
Relational Algebra in Dbms
TO
RELATIONAL
ALGEBRA
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.
• These operations enable a user to specify basic
retrieval requests (or queries)
Cont.
• The fundamental operations in the relational
algebra are select, project, union, set difference,
Cartesian product, and rename
LNAME, FNAME,SALARY(EMPLOYEE)
Composition of Relational Operations
Example
• “Find the name of all instructors in the
Physics department.
name ( dept name =“Physics”
(instructor))
RENAME
• The general RENAME operation can be
expressed by any of the following
forms:
– S(R) changes:
• the relation name only to S
– (B1, B2, …, Bn )(R) changes:
• the column (attribute) names only to B1, B1,
…..Bn
– S (B1, B2, …, Bn )(R) changes both:
• the relation name to S, and
Relational Algebra Operations
Set Theory
• Union
• Intersection
• Set Difference / Minus
• Cartesian Product
UNION
• It is a Binary operation, denoted by
15
INTERSECTION
• INTERSECTION is denoted by
r x s:
SQL Built in Functions
NUMERIC FUNCTIONS:
• abs(n) – returns absolute value of n
SQL> select abs(-2) from dual; - 2
• ceil(n) – ceil(3.78) - 4
• floor(n) – floor(2.4) - 2
• sqrt(n)
• power(n,m)
SQL> select power(5,2) from dual;
- 25
• mod(a,b)
SQL Built in Functions
String/Character FUNCTIONS:
• initcap(string)
SQL > select initcap(‘hello’) from dual; - Hello
• upper(string)
• lower(string)
• ltrim(string)
SQL > select ltrim(‘ hello’) from dual; - hello
• rtrim(string)
• replace( )
SQL > select replace(‘hello’, ’ll’, ’r’) from dual; - hero
• length( )
SQL > select length(‘hello’) from dual; - 5