Relational algebra
Upcoming SlideShare
Loading in...5
×
 

Relational algebra

on

  • 1,078 views

 

Statistics

Views

Total Views
1,078
Views on SlideShare
1,078
Embed Views
0

Actions

Likes
0
Downloads
47
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Relational algebra Relational algebra Presentation Transcript

  • .
    • RELATIONAL ALGEBRA IS A COLLECTION OF OPERATIONS TO MANIPULATE OR ACCESS TABLES.
    • IT IS A PROCEDURAL LANGUAGE WITH OPERATIONS PERFORMED ON ONE OR MORE EXISTING RELATIONS TO DERIVE RESULTING RELATIONS WITHOUT CHANGING THE ORIGINAL RELATIONS.
    • RELATIONAL ALGEBRA OPERATINS CAN BE DIVIDED INTO TWO GROUPS i.e
    • SET-ORIENTED OPERATIONS
    • NATIVE(SPECIAL) RELATIONAL OPERATIONS .
    BASICS OF RELATIONAL ALGEBRA
  • BASIC SET ORIENTED OPERATIONS NATIVE RELATIONAL OPERATIONS NAME SYMBOL SELECTION σ PROJECTION Π JOIN DIVISION ÷ RENAME ρ ASSIGNMENT 
  • UNION A B R=A U B ROLL.NO NAME 12505 SHARAN 12506 SANGEETA 12507 SHYNA ROLL.NO NAME 12502 PRABJOT 125O7 SHYNA 12520 POOJA 12521 RINKI ROLL.NO NAME 12502 PRABJOT 12505 SHARAN 12506 SANGEETA 12507 SHYNA 12520 POOJA 12521 RINKI
  • INTERSECTION A B R=A ∩ B ROLL.NO NAME 12502 PRABJOT 12505 SHARAN 12507 SHYNA 12521 RINKI ROLL.NO NAME 12507 SHYNA 12519 POOJA 12521 RINKI ROLL.NO NAME 12507 SHYNA 12521 RINKI
  • DIFFERENCE B A R=A-B R=B-A ROLL.NO NAME 12502 PRABJOT 12505 SHARAN 12507 SHYNA 12521 RINKI ROLL.NO NAME 12507 SHYNA 12519 POOJA 12514 NEETU 12521 RINKI ROLL.NO NAME 12502 PRABJOT 12505 SHARAN ROLL.NO NAME 12519 POOJA 12514 NEETU
  • CARTESIAN PRODUCT A B R=A × B ROLL.NO NAME 12502 PRABJOT 12505 SHARAN 12507 SHYNA 12521 RINKI ROLL.NO NAME 12507 SHYNA 12519 POOJA ROLL.NO NAME ROLL.NO NAME 12502 PRABJOT 12507 SHYNA 12502 PRABJOT 12519 POOJA 12505 SHARAN 12507 SHYNA 12505 SHARAN 12519 POOJA 12507 SHYNA 12507 SHYNA 12507 SHYNA 12519 POOJA 12521 RINKI 12507 SHYNA 12521 RINKI 12521 POOJA
  • EMPLOYEE SELECTION RESULTING TABLE σ AGE >32 (EMPLOYEE) ID NAME SALARY AGE 101 AMIT 4500 30 102 AJAY 5000 35 105 JOHN 5000 36 106 ABHI 4000 28 107 ALI 4800 31 108 SUNIL 3500 33 ID NAME SALARY AGE 102 AJAY 5000 35 105 JOHN 5000 36 108 SUNIL 3500 33
  • PROJECTION EMPLOYEE RESULTING TABLES A. π ID (EMPLOYEE) B. π NAME,AGE (EMPLOYEE) B A ID NAME SALARY AGE 101 AMIT 4500 30 102 AJAY 5000 35 105 JOHN 5000 36 106 ABHI 4000 28 107 ALI 4800 31 108 SUNIL 3500 33 109 JOHN 4600 29 NAME AGE AMIT 30 AJAY 35 JOHN 36 ABHI 28 ALI 31 SUNIL 33 JOHN 29 ID 101 102 105 106 107 108 109
  • COURSE(C) S JOIN RESULTING TABLE( EQUI-JOIN ) COURSE=C_ID (C) STU(S) ROLL.NO NAME COURSE 101 PIYUSH M-01 102 SUMIT M-02 103 SHEENA M-04 104 RITU M-03 C_ID C_NAME C_DUR M-01 MBA(HR) 2 M-02 MSC(PHY) 2 M-03 MSC(IT) 2 M-04 MCA 3 ROLL.NO NAME COURSE 101 PIYUSH M-01 102 SUMIT M-02 103 SHEENA M-04 104 RITU M-03 C_ID C_NAME C_DUR M-01 MBA(HR) 2 M-02 MSC(PHY) 2 M-04 MCA 3 M-03 MSC(IT) 2
  • COURSE(C) NATURAL JOIN ON S AND C NATURAL JOIN(INNER JOIN) STU(S) ROLL.NO NAME COURSE 101 PIYUSH M-01 102 SUMIT M-02 103 SHEENA M-04 104 RITU M-03 C_NAME C_DUR MBA(HR) 2 MSC(PHY) 2 MCA 3 MSC(IT) 2 ROLL.NO NAME COURSE 101 PIYUSH M-01 102 SUMIT M-02 103 SHEENA M-04 104 RITU M-03 C_ID C_NAME C_DUR M-01 MBA(HR) 2 M-02 MSC(PHY) 2 M-03 MSC(IT) 2 M-04 MCA 3
  • DIVISION MAIN R1 SUB2 SUB3 RESULTING TABLES R3 R3  MAIN ÷ SUB3 R2 R1  MAIN ÷ SUB1 R2  MAIN ÷ SUB2 SUB1 ASSIGNMENT A B A1 B1 A3 B2 A2 B3 A2 B1 A1 B3 A3 B3 A3 B1 B B1 B3 B B2 B B2 B3 A A1 A2 A3 A A3 A A3
  • ρ
    • Rename operation results in either a new relation or attributes of a relation or both .
    RENAME x (R) ρ x(A1,A2,A3…An) (R)
  • ADDITIONAL RELATIONAL OPERATORS
    • To enhance the expressive power of relational algebra, we need some additional Relational operations to perform the requests which cannot be performed with the basic relational algebra operations .
    • These include
    • Aggregate functions(sum ,average ,max ,count etc)
    • Grouping
    • Outer join etc
  • Aggregate functions and grouping (R) COUNT EMP_ID, SUM SALARY £ (R) DEP_ID £ COUNT EMP_ID, MAXIMUM SALARY (R) EMP_ID NAME DEP_ID SALARY 250 RAVI 10 5600 251 ANUJ 11 4000 252 JOHN 13 10000 253 AJIT 10 4500 254 RAVI 13 9000 256 AJAY 11 5000 257 ANUJ 11 3000 258 JOHN 10 2000 DEP_ID COUNT EMP_ID SUM SALARY 10 3 12100 11 3 12000 13 2 19000 COUNT EMP_ID MAX SALARY 9 10000
  • In outer join ,the rows in one relation having no matching rows in the other Relation will also appear in the resulting table with nulls in other attributes positions instead of being ignored . OUTER JOIN
    • Outer join can be of one of the following types:
    • Left outer join
    • Right outer join
    • Full outer join
  • LEFT OUTER JOIN EMP(E) DEPT(D) E D EMP_ID E_NAME AGE DEP_NO 101 AJAY 28 10 103 AMIT 33 11 104 PIYUSH 30 10 107 AJIT 23 NULL DEP_ID D_NAME 10 CREDIT 11 LOAN 12 CASH EMP_ID E_NAME AGE D_NAME 101 AJAY 28 CREDIT 103 AMIT 33 LOAN 104 PIYUSH 30 CREDIT 107 AJIT 23 NULL
  • RIGHT OUTER JOIN EMP(E) DEPT(D) E D DEP_ID D_NAME 10 CREDIT 11 LOAN 12 CASH EMP_ID E_NAME AGE DEP_NO 101 AJAY 28 10 103 AMIT 33 11 104 PIYUSH 30 10 107 AJIT 23 NULL EMP_ID E_NAME AGE D_NAME 101 AJAY 28 CREDIT 103 AMIT 33 LOAN 104 PIYUSH 30 CREDIT NULL NULL NULL CASH
  • FULL OUTER JOIN EMP(E) DEPT(D) E D DEP_ID D_NAME 10 CREDIT 11 LOAN 12 CASH EMP_ID E_NAME AGE DEP_NO 101 AJAY 28 10 103 AMIT 33 11 104 PIYUSH 30 10 107 AJIT 23 NULL EMP_ID E_NAME AGE D_NAME 101 AJAY 28 CREDIT 103 AMIT 33 LOAN 104 PIYUSH 30 CREDIT 107 AJIT 23 NULL NULL NULL NULL CASH