180 likes | 229 Views
Relational Data Model. Ervi Bongso Alan Fernando CS157A. 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: ⋈
E N D
Relational Data Model Ervi Bongso Alan Fernando CS157A
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
Unary: (selection) Extract a horizontal subset of tuples from a relation that matches specified search criteria. Age≥34(Person) Person Age=Weight(Person)
Unary: (projection) Extract a vertical subset of columns from a relation. Employee ∏name(Employee)
(selection), (projection) Employee ∏name(бSalary>80,000(Employee))
Binary: (union) Adds the tuples from 1 relation to those from a second relation to produce a third relation. Student Professor Student Professor
Binary: - (difference) Contains the tuples from the first relation that are not in the second relation. Student Professor Professor - Student Student - Professor
Binary: (intersection) Contains tuples common to the two relations. Student Professor Student Professor
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
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)
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
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.
Views and Materialized Views (cont.) • 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.
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/cs157/cs157a.html