Presentation is loading. Please wait.

Presentation is loading. Please wait.

Database Management System

Similar presentations


Presentation on theme: "Database Management System"— Presentation transcript:

1 Database Management System
Lecture - 17 © Virtual University of Pakistan

2 © Virtual University of Pakistan
Five Basic Operators Unary Operators Select Project © Virtual University of Pakistan

3 © Virtual University of Pakistan
Five Basic Operators Binary Operators Union Set Difference Cartesian Product © Virtual University of Pakistan

4 © Virtual University of Pakistan
Select Selects tuples that satisfy a given predicate Notation is Greek symbol sigma:  PREDICATE(RELATION) © Virtual University of Pakistan

5 © Virtual University of Pakistan
Select To process a selection, Look at each tuple See if we have a match (based on the condition) © Virtual University of Pakistan

6 © Virtual University of Pakistan
Select The Degree of the resulting relation is the same as the degree of the relation | σ | = | r(R) | σ is Commutative σc1 (σc2(R)) = σc2 (σc1(R)) © Virtual University of Pakistan

7 © Virtual University of Pakistan
Selection Example stId stName stAdr prName curSem S1020 Sohail Dar H#14, F/8-4,Islamabad. MCS 4 S1038 Shoaib Ali H#23, G/9-1,Islamabad BCS 3 S1015 Tahira Ejaz H#99, Lala Rukh Wah. 5 S1018 Arif Zia H#10, E-8, Islamabad. BIT © Virtual University of Pakistan

8 © Virtual University of Pakistan
Selection Example σ Curr_Sem > 3 (STUDENT) σ Studid = ‘S1038’ (STUDENT) © Virtual University of Pakistan

9 Selection Example Cont’d)
FacID Fname Address Salary Rank F2345 Usman H#Car409 21000 lecturer F3456 Tahir H#Bac100 23000 Asso Prof F4567 Ayesha H#Car301 27000 F5678 Samad H#Irv342 32000 Professor © Virtual University of Pakistan

10 Selection Example Cont’d)
σ Salary > (FAC) σ(Salary>26000) and (Rank=‘Asso Prof’) (FAC) © Virtual University of Pakistan

11 © Virtual University of Pakistan
Projection Unary operation that returns its argument relation with certain attributes left out. Any duplicate rows are eliminated. © Virtual University of Pakistan

12 © Virtual University of Pakistan
Projection Notation  a1, a2, ..., ak (R) where a1 ... ak are attribute names and R is a relation name © Virtual University of Pakistan

13 © Virtual University of Pakistan
Projection Works on a single relation R and defines a relation that contains a vertical subset of R, extracting the values of specified attributes and eliminating duplicates. © Virtual University of Pakistan

14 © Virtual University of Pakistan
Projection Reduces duplicate columns created by cross product. Creates a New relation © Virtual University of Pakistan

15 © Virtual University of Pakistan
Projection Example FacID Fname Dept Salary Rank F2345 Usman CSE 21000 lecturer F3456 Tahir 23000 Asso Prof F4567 Ayesha ENG 27000 F5678 Samad MNG 32000 Professor © Virtual University of Pakistan

16 © Virtual University of Pakistan
Projection Example  FacID, Salary (Faculty)  Fname, Rank (Faculty)  Facid, Salary,Rank (Faculty) © Virtual University of Pakistan

17 © Virtual University of Pakistan
Union Assuming R & S are union compatible… Union: R ⋃ S is the set of tuples in either R or S or both. © Virtual University of Pakistan

18 © Virtual University of Pakistan
Union Since it is a set, there are no duplicate tuples Union is Commutative R U S = S U R © Virtual University of Pakistan

19 © Virtual University of Pakistan
Union Example Course1 CID ProgID Cred_Hrs CourseTitle C2345 P1245 3 Operating Sytems C3456 4 Database Systems C4567 P9873 Financial Management C5678 Money & Capital Market Course2 CID ProgID Cred_Hrs CourseTitle C4567 P9873 4 Financial Management C8944 P4567 Electronics © Virtual University of Pakistan

20 © Virtual University of Pakistan
Union Example Course 1 U Course 2 CID ProgID Cred_Hrs CourseTitle C2345 P1245 3 Operating Sytems C3456 4 Database Systems C4567 P9873 Financial Management C5678 Money & Capital Market C8944 P4567 4 Electronics © Virtual University of Pakistan

21 © Virtual University of Pakistan
Intersection (⋂) Assuming that R & S are union compatible Intersection: R ⋂ S is the set of tuples in both R and S © Virtual University of Pakistan

22 © Virtual University of Pakistan
Intersection (⋂) Intersection is Commutative R ⋂ S = S ⋂ R © Virtual University of Pakistan

23 Intersection (⋂) Example
Course 1 ⋂ Course 2 CID ProgID Cred_Hrs CourseTitle C4567 P9873 4 Financial Management © Virtual University of Pakistan

24 © Virtual University of Pakistan
Difference (-) Difference: R – S is the set of tuples that appear in R but do not appear in S. © Virtual University of Pakistan

25 Difference (-) Example
Course1 – Course2 CID ProgID Cred_Hrs CourseTitle C2345 P1245 3 Operating Sytems C3456 4 Database Systems C5678 P9873 Money & Capital Market © Virtual University of Pakistan

26 © Virtual University of Pakistan
Cartesian Product (X) Sets do not have to be union compatible. R(A1, A2, …, AN) X S(B1, B2, …, BM) is © Virtual University of Pakistan

27 © Virtual University of Pakistan
Cartesian Product (X) Q (A1, A2, …, An, B1, B2, …, Bm) If R has C tuples and S has D tuples, the result is C*D tuples. © Virtual University of Pakistan

28 © Virtual University of Pakistan
Cartesian Product (X) Also called “cross product” Note that union, intersection and cross product are commutative and associative © Virtual University of Pakistan

29 Cartesian Product (X) Example
Course X Registration Course Registration CID CourseTitle SID StudName C3456 Database Systems C4567 Financial Management C5678 Money & Capital Market S101 Ali Tahir S103 Farah Hasan © Virtual University of Pakistan

30 Cartesian Product (X) Example
CID CourseTitle SID StudName C3456 Database Systems C4567 Financial Management C5678 Money & Capital Market S101 Ali Tahir AliTahr S101 Ali Tahir S103 Farah Hasan C3456 Database Systems C4567 Financial Management C5678 Money & Capital Market S103 Farah Hasan © Virtual University of Pakistan

31 © Virtual University of Pakistan
Join Operation © Virtual University of Pakistan

32 © Virtual University of Pakistan
Lecture 17 ends here… © Virtual University of Pakistan


Download ppt "Database Management System"

Similar presentations


Ads by Google