Relational Operators - PowerPoint PPT Presentation

1 / 18
About This Presentation
Title:

Relational Operators

Description:

Relational operations are set level, meaning that they operate on multiple rows, ... Any column value in a table can be referenced, not just keys. ... – PowerPoint PPT presentation

Number of Views:335
Avg rating:3.0/5.0
Slides: 19
Provided by: wongmo
Category:

less

Transcript and Presenter's Notes

Title: Relational Operators


1
Relational Operators
2
Relational Operators
Properties
  • Relational operations are specified using
    Structured Query Language (SQL) -- a standard for
    relational database access.
  • Relational operations are set level, meaning that
    they operate on multiple rows, rather than one
    record at a time.
  • SQL is non-procedural, meaning that the user
    specifies what data is to be retrieved rather
    than how to retrieve the data.

3
Relational Operators
Properties
  • Each operator takes one or more tables as it
    operand(s) and produces a table as its result.
  • Any column value in a table can be referenced,
    not just keys.
  • Operations can be combined to form complex
    operations.

4
Operations on a DBMS
  • Can be specified using
  • Relational Algebra operations (what we learn now)
  • Are usually divided into two groups
  • Set theory operations
  • Operations specifically developed for relational
    databases
  • But are considered too technical for ordinary
    users, hence the birth of SQL
  • They are written as a sequence of steps, when
    executed produce the results
  • Hence the user must give say how and not what
    is needed
  • Relational calculus
  • Another formal query language which gives what
    is required, and not how.
  • Eg- t.FNAME,t.LNAMEEMPLOYEE(t) and
    t.SALARYgt500
  • SELECT T.FNAME, T.LNAME
  • FROM EMPLOYEE AS T
  • WHERE T.SALARYgt500
  • SQL

5
Relational Operators
Selection horizontal subset of a table
Sales-Emp ?D-No7 (Employee)
6
Projection vertical subset of a table
Emp-Names ?E-No, E-Name (Employee)
7
Cartesian Product Creates a single table from
two tables.
Emp-Info Employee ? E.D-NoD.D-No Department
8
Join Creates a single table from two tables.
Department
D-No D-Name M-No 4 Finance 857
7 Sales 179
EquiJoin
Emp-Info Employee E.D-NoD.D-No Department
9
Joins
  • The most common join is where we only use the
    equal operator , and is known as equijoin.
  • We can use other operator (,lt,gt,lt, etc) for
    the join condition also
  • The natural join () can be used to get rid of
    the additional attribute in an equijoin
    condition.
  • In a natural join only the matching tuples are
    displayed. The left outer join and right outer
    join and full outer joincan be used to find
    even non matching tuples (Refer EN pp229)

10
Natural Join Creates a single table from two
tables.
Emp-Info Employee ? E.D-NoD.D-No Department
11
Relational Operators
Other operators
Set operations from mathematical set theory
12
Set Operators
Stu-Inst Student ? Instructor
13
Set Operators
Stu-Inst Student ? Instructor
14
Set Operators
Stu-Inst Student - Instructor Inst-Stu
Instructor - Student
15
Complete Set of Relational Algebra Operations
It has been proved that ?, ?, ?, ?, ? is a
complete set.
Any other relational algebra operator can be
expressed in terms of the above
operators. E.g. R Ç S (R È S) ? ( ( R ? S) È
(S ? R) )
16
Division operator
  • Refer Elmasri Navathe pp 224

Rename operator
  • Refer Elmasri Navathe pp 215

R(FirstName,LastName,Salary) ?Fname,Lname,Sal
(Employee) Can be useful for set related
operations.
17
Relational Operators
Because the result of every relational operation
is a table, operators can be combined to create
complex operations. For example
Select Project
A B
B
A

Project Select Join
18
Relational Operators
Get course names thought by lecturer Dr
Kodikara course(cno, cname, lecturer) employee(e
mpno, ename, designation)
Emp_Kodi ? enemeDr. Kodikara
Employee Courses ? cname,
lecturer Course Kodi_courses Emp_Kodi
empno lecture Courses
Kodi_courses
Course
Employee

Select Project N-Join
Write a Comment
User Comments (0)
About PowerShow.com