Presentation is loading. Please wait.

Presentation is loading. Please wait.

Relational Data Model Ervi Bongso Alan Fernando CS157A.

Similar presentations


Presentation on theme: "Relational Data Model Ervi Bongso Alan Fernando CS157A."— Presentation transcript:

1 Relational Data Model Ervi Bongso Alan Fernando CS157A

2 Outline Sect. 6.4, Intro to Relational Algebra Comprise of: Unary Operations:  (selection) and  (projection) Binary Operations:  (union), - (difference),  (intersection), x (cartesian product) Natural Join: * and Join: ⋈ Sect. 6.5, Views and Materialized Views Sect. 6.6, Info of Preservation Issue

3 Unary:  (selection) Extract a horizontal subset of tuples from a relation that matches specified search criteria. NameAgeWeight Harry3480 Sally2864 George2970 Helena54 Peter3480 NameAgeWeight Harry3480 Helena54 Peter3480  Age≥34 (Person) NameAgeWeight Helena54  Age=Weight (Person) Person

4 Unary:  (projection) Extract a vertical subset of columns from a relation. NameAgeSalary Harry3480,000 Sally2890,000 George2970,000 Helena5454,280 Peter3440,000 Name Harry Sally George Helena Peter Employee∏ name (Employee)

5  (selection),  (projection) Name Sally ∏ name (б Salary>80,000 (Employee)) NameAgeSalary Harry3480,000 Sally2890,000 George2970,000 Helena5454,280 Peter3440,000 Employee

6 Binary:  (union) Adds the tuples from 1 relation to those from a second relation to produce a third relation. FNLN SusanYao RameshShah BarbaraJones AmyFord JimmyWang FNLN JohnSmith RicardoBrown SusanYao FrancisJohnson RameshShah StudentProfessor FNLN SusanYao RameshShah BarbaraJones AmyFord JimmyWang JohnSmith RicardoBrown FrancisJohnson Student  Professor

7 Binary: - (difference) Contains the tuples from the first relation that are not in the second relation. FNLN SusanYao RameshShah BarbaraJones AmyFord JimmyWang FNLN JohnSmith RicardoBrown SusanYao FrancisJohnson RameshShah StudentProfessor FNLN BarbaraJones AmyFord JimmyWang Student - Professor Professor - Student FNLN JohnSmith RicardoBrown FrancisJohnson

8 Binary:  (intersection) Contains tuples common to the two relations. FNLN SusanYao RameshShah BarbaraJones AmyFord JimmyWang FNLN JohnSmith RicardoBrown SusanYao FrancisJohnson RameshShah StudentProfessor FNLN SusanYao RameshShah Student  Professor

9 Binary: x (cartesian product) Does not have to be union compatible. Produces a new element by combining every tuple from one set with every tuple from the other set. R×S = R(A1,A2,...,An) × S(B1,B2,...Bm) = Q(A1,A2,...,An,B1,B2,...Bm) with degree n + m attributes

10 Join: ⋈ Used to combine related tuples from two relations into single tuples. Allows us to process relationships among relations. Example: to retrieve the name of the manager of each department: Step1) Dept_mgr ← Dept ⋈ Mgr_Ssn=SsnEmployee Step2) Result ← πDname, Lname, Fnamer(Dept_mgr)

11 Example  Join: ⋈ EMPLOYEE FnameMinitLnameSsn JohnBSmith1.23E+08 FranklinTWong3.33E+08 AliciaJZelaya1E+09 JenniferSWallace9.88E+08 RameshKNarayan6.67E+08 JoyceAEnglish4.53E+08 AhmadVJabbar9.88E+08 JamesEBorg8.89E+08 DEPARTMENT DnameDnumberMgr_ssn Research53.33E+08 Administration49.88E+08 Headquarters18.89E+08 DEPT_MGR DnameDnumb er Mgr_SSN...FnameMinitLnameSSN Research53.33E+08...FranklinTWong3.33E+08 Administratn49.88E+08...JenniferSWallace9.88E+08 Headquarters18.89E+08...JamesEBorg8.89E+08

12 Natural Join: * Created to get rid of the second attribute. Requires that the two join attributes have the same name. If not, renaming must first be applied. Example: DEPT_LOCS ← DEPARTMENT * DEPT_LOCATIONS

13 Example  Natural Join: * DEPARTMENT DnameDnumberMgr_ssn Research53.33E+08 Administration49.88E+08 Headquarters18.89E+08 DEPT_LOCATIONS DnumberDlocation 1Houston 4Stafford 5Bellaire 5Sugarland 5Houston DEPT_LOCS DnameDnumberMgr_ssnDlocation Headquarters18.89E+08Houston Administration49.88E+08Stafford Research53.33E+08Bellaire Research53.33E+08Sugarland Research53.33E+08Houston

14 Views and Materialized Views Views Allows the same data to be seen by different users in different ways at the same time. Provides security Hides data complexity from the user. Growth and Restructuring Growth is expansion of existing relation schema. Restructuring is changes other than growth.

15 Materialized Views (Snapshot) Stored in the database. Refreshed when updates occur. Used to freeze data. Deleted when it is not used for a period of time. Views and Materialized Views (cont.)

16 Issue of Info Reservation

17 References Elamstri and Navathe, Fundamentals of Database Systems, 5th ed., Addison-Wesley, 2008 Umanath and Scamell, Data Modeling and Database Design, Thomson 2007 http://www.cs.sjsu.edu/faculty/lee/cs1 57/cs157a.html

18 Thank You!


Download ppt "Relational Data Model Ervi Bongso Alan Fernando CS157A."

Similar presentations


Ads by Google