Upcoming SlideShare
×

# Relational algebra

1,898 views
1,750 views

Published on

Published in: Education
1 Like
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

Views
Total views
1,898
On SlideShare
0
From Embeds
0
Number of Embeds
8
Actions
Shares
0
182
0
Likes
1
Embeds 0
No embeds

No notes for slide

### Relational algebra

1. 1. .
2. 2. <ul><li>RELATIONAL ALGEBRA IS A COLLECTION OF OPERATIONS TO MANIPULATE OR ACCESS TABLES. </li></ul><ul><li>IT IS A PROCEDURAL LANGUAGE WITH OPERATIONS PERFORMED ON ONE OR MORE EXISTING RELATIONS TO DERIVE RESULTING RELATIONS WITHOUT CHANGING THE ORIGINAL RELATIONS. </li></ul><ul><li>RELATIONAL ALGEBRA OPERATINS CAN BE DIVIDED INTO TWO GROUPS i.e </li></ul><ul><li>SET-ORIENTED OPERATIONS </li></ul><ul><li>NATIVE(SPECIAL) RELATIONAL OPERATIONS . </li></ul>BASICS OF RELATIONAL ALGEBRA
3. 3. BASIC SET ORIENTED OPERATIONS NATIVE RELATIONAL OPERATIONS NAME SYMBOL SELECTION σ PROJECTION Π JOIN DIVISION ÷ RENAME ρ ASSIGNMENT 
4. 4. 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
5. 5. 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
6. 6. 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
7. 7. 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
8. 8. 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
9. 9. 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
10. 10. 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
11. 11. 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
12. 12. 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
13. 13. ρ <ul><li>Rename operation results in either a new relation or attributes of a relation or both . </li></ul>RENAME x (R) ρ x(A1,A2,A3…An) (R)
14. 14. ADDITIONAL RELATIONAL OPERATORS <ul><li>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 . </li></ul><ul><li>These include </li></ul><ul><li>Aggregate functions(sum ,average ,max ,count etc) </li></ul><ul><li>Grouping </li></ul><ul><li>Outer join etc </li></ul>
15. 15. 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
16. 16. 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 <ul><li>Outer join can be of one of the following types: </li></ul><ul><li>Left outer join </li></ul><ul><li>Right outer join </li></ul><ul><li>Full outer join </li></ul>
17. 17. 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
18. 18. 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
19. 19. 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
{"found_math": false, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 0, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0}