Database System Concepts, 5 th Ed. ©Silberschatz, Korth and Sudarshan See www.db-book.com for conditions on re-usewww.db-book.com Chapter 2: Relational.

Slides:



Advertisements
Similar presentations
CS 319: Theory of Databases: C4
Advertisements

More Slides on “Division Operation” in Relational Algebra Query Language (& together with examples on Assignment operation)
Ver 1,12/09/2012Kode :CCs 111,sistem basisdataFASILKOM Chapter 2: Relational Model Database System Concepts, 5th Ed. ©Silberschatz, Korth and Sudarshan.
Chapter 2 Relational Model (part II) Hankz Hankui Zhuo
©Silberschatz, Korth and Sudarshan3.1Database System Concepts Chapter 3: Relational Model Structure of Relational Databases Relational Algebra Extended.
©Silberschatz, Korth and Sudarshan3.1Database System Concepts Chapter 3: Relational Model Structure of Relational Databases Relational Algebra Tuple Relational.
©Silberschatz, Korth and Sudarshan3.1Database System Concepts Chapter 3: Relational Model Structure of Relational Databases Relational Algebra Tuple Relational.
Database System Concepts, 5 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 2: Relational.
Relational Algebra and SQL Prof. Sin-Min Lee Department of Computer Science San Jose State University.
SPRING 2004CENG 3521 E-R Diagram for the Banking Enterprise.
Database System Concepts, 5 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 2: Relational.
Midterm 2 Revision Prof. Sin-Min Lee Department of Computer Science San Jose State University.
Instructor: Mohamed Eltabakh
Slides adapted from A. Silberschatz et al. Database System Concepts, 5th Ed. Relational Model Database Management Systems I Alex Coman, Winter 2006.
Relational Model. 2 Structure of Relational Databases Fundamental Relational-Algebra-Operations Additional Relational-Algebra-Operations Extended Relational-Algebra-Operations.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 6: Formal Relational.
©Silberschatz, Korth and Sudarshan3.1Database System Concepts Chapter 3: Relational Model Structure of Relational Databases Relational Algebra Tuple Relational.
PMIT-6102 Advanced Database Systems By- Jesmin Akhter Assistant Professor, IIT, Jahangirnagar University.
Database System Concepts, 5 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com 1 Chapter 2: Relational.
Relational Model: Examples. Banking Example branch (branch_name, branch_city, assets) customer (customer_name, customer_street, customer_city) account.
©Silberschatz, Korth and Sudarshan2.1Database System Concepts Chapter 2: Relational Model Structure of Relational Databases Relational Algebra.
Database System Concepts, 5 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 2: Relational.
©Silberschatz, Korth and Sudarshan2.1Database System Concepts - 5 th Edition, Oct 5, 2006 Outer Join n An extension of the join operation that avoids loss.
Chapter 6: Formal Relational Query Languages. 6.2 Chapter 6: Formal Relational Query Languages Relational Algebra Tuple Relational Calculus Domain Relational.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 6: Formal Relational.
Database System Concepts, 5 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 2: Relational.
CIS552Relational Model1 Structure of Relational Database Relational Algebra Extended Relational-Algebra-Operations Modification of the Database.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com ICOM 5016 – Introduction.
3.1Database System Concepts Chapter 3: Relational Model Structure of Relational Databases Relational Algebra Tuple Relational Calculus Domain Relational.
Midterm 2 Revision Prof. Sin-Min Lee Department of Mathematics and Computer Science San Jose State University.
1 Session 3 Welcome: To session 3-the fifth learning sequence “ Relational algebra “ Recap : In the previous learning sequences, we discussed the eight.
Computing & Information Sciences Kansas State University Monday, 08 Sep 2008CIS 560: Database System Concepts Lecture 5 of 42 Monday, 08 September 2008.
Database System Concepts, 5 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Relational Model.
Advanced Database Systems By- Jesmin Akhter Assistant Professor, IIT, Jahangirnagar University.
©Silberschatz, Korth and Sudarshan3.1Database System Concepts Chapter 3: Relational Model Structure of Relational Databases Relational Algebra Extended.
Chapter 2: Relational Model. 2.2 Chapter 2: Relational Model Structure of Relational Databases Fundamental Relational-Algebra-Operations Additional Relational-Algebra-Operations.
©Silberschatz, Korth and Sudarshan2.1Database System Concepts - 5 th Edition, Oct 5, 2006 Example.
Chapter 2: Relational Model. 2.2Unite International CollegeDatabase Management Systems Chapter 2: Relational Model Structure of Relational Databases Fundamental.
Chapter 2: Relational Model II Relational Algebra basics Relational Algebra basics.
2.1 Chapter 2: Relational Model. 2.2 Chapter 2: Relational Model Structure of Relational Databases Fundamental Relational-Algebra-Operations Additional.
Source: Database System Concepts, Silberschatz etc Edited: Wei-Pang Yang, IM.NDHU, Introduction to Database CHAPTER 2 RELATIONAL MODEL 2.1.
©Silberschatz, Korth and Sudarshan3.1Database System Concepts Chapter 3: Relational Model Structure of Relational Databases Relational Algebra Extended.
Database System Concepts, 5 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 2: Relational.
Database System Concepts, 5 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 2: Relational.
Database System Concepts, 5th Ed. Bin Mu at Tongji University Chapter 5: Other Relational Languages.
Midterm 2 Revision Prof. Sin-Min Lee Department of Computer Science San Jose State University.
Database System Concepts, 5 th Ed. Bin Mu at Tongji University Chapter 2: Relational Model.
Computing & Information Sciences Kansas State University Wednesday, 03 Sep 2008CIS 560: Database System Concepts Lecture 3 of 42 Wednesday, 03 September.
©Silberschatz, Korth and Sudarshan1Database System Concepts The Relational Model Structure of Relational Databases Relational Algebra.
Relational Algebra HW2 Turn in as a hardcopy at the start of next class period. You may work this assignment in groups.
ICOM 5016 – Introduction to Database Systems Lecture 6 Dr. Manuel Rodriguez Department of Electrical and Computer Engineering University of Puerto Rico,
Database System Concepts, 5 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 2: Relational.
1 Session 3 Welcome: To session 3-the fourth learning sequence “Relational algebra “ Recap : In the previous learning sequences, we discussed the four.
ASET Relational Algebra continues…. ASET Rename Operation Allows us to name, and therefore to refer to, the results of relational-algebra expressions.
IS 230Lecture 7Slide 1 Relational Algebra Lecture 8 Text Book – Chapter.
Chapter 3: Relational Model III Additional Relational Algebra Operations Additional Relational Algebra Operations Views Views.
International Computer Institute, Izmir, Turkey Relational Model Asst.Prof.Dr.İlker Kocabaş UBİ502 at
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 6: Formal Relational.
Query Languages Language in which user requests information from the database. Categories of languages Procedural Non-procedural, or declarative “Pure”
Database System Concepts, 5 th Ed. ©Silberschatz, Korth and Sudarshan Chapter 2: Relational Model.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 6: Formal Relational.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 6: Formal Relational.
International Computer Institute, Izmir, Turkey Relational Model Asst.Prof.Dr.İlker Kocabaş UBİ502 at
Session 3 Welcome: To session 3-the fourth learning sequence
Midlands State University Topic: Relational DB Model
Chapter 3: Relational Model III
Lecture 4 of 42 Relational Joins Wednesday, 30 January 2008
Instructor: Mohamed Eltabakh
Relational Algebra.
Chapter 2: Relational Model
Presentation transcript:

Database System Concepts, 5 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 2: Relational Model

©Silberschatz, Korth and Sudarshan2.2Database System Concepts - 5 th Edition, Oct 5, 2006 Examples Consider the following relations: Student(roll, name, address, phone) Course(code, title) Registered(roll, code) Find out the course code in which at least one student is registered π code ( Registered) Find out the titles of registered courses π title (  Course.code = Registered.code (Course X Registered )) Find out the course code in which no student is registered π code ( Course ) - π code ( Registered )

©Silberschatz, Korth and Sudarshan2.3Database System Concepts - 5 th Edition, Oct 5, 2006 Examples Find out the student names and course titles they registered to π name, title (  Student.roll = Registered.roll^ Registered.code=Course.code (Student X Registered X Course)) Consider the following relations: Student(roll, name, address, phone) Course(code, title) Registered(roll, code) Name of student who are registered to ‘Database’ or ‘Algorithms’ course π name (  Student.roll = Registered.roll^ Registered.code=Course.code (Student X Registered X (σ title=’Database’ Course)) ) ∪ π name (  Student.roll = Registered.roll^ Registered.code=Course.code (Student X Registered X (σ title=’Algorithm’ Course)) )

©Silberschatz, Korth and Sudarshan2.4Database System Concepts - 5 th Edition, Oct 5, 2006 Rename Operation Allows us to name and therefore to refer to the results of relational- algebra expressions. Allows us to refer to a relation by more than one name. Example:  x (E) returns the expression E under the name X If a relational-algebra expression E has arity n, then returns the result of expression E under the name X, and with the attributes renamed to A 1, A 2, …., A n.

©Silberschatz, Korth and Sudarshan2.5Database System Concepts - 5 th Edition, Oct 5, 2006 Banking Example branch (branch_name, branch_city, assets) customer (customer_name, customer_street, customer_city) account (account_number, branch_name, balance) loan (loan_number, branch_name, amount) depositor (customer_name, account_number) borrower (customer_name, loan_number)

©Silberschatz, Korth and Sudarshan2.6Database System Concepts - 5 th Edition, Oct 5, 2006 Example Queries Find the largest account balance Strategy:  Find those balances that are not the largest –Rename account relation as d so that we can compare each account balance with all others  Use set difference to find those account balances that were not found in the earlier step. The query is:  balance (account) -  account.balance (  account.balance < d.balance (account x  d (account)))

©Silberschatz, Korth and Sudarshan2.7Database System Concepts - 5 th Edition, Oct 5, 2006 Example Queries Find the names of all customers who have a loan at the Dhanmondi branch. Query 2  customer_name (  loan.loan_number = borrower.loan_number ( (  branch_name = “Dhanmondi ” (loan)) x borrower)) Query 1  customer_name (  branch_name = “Dhanmondi” (  borrower.loan_number = loan.loan_number (borrower x loan)))

©Silberschatz, Korth and Sudarshan2.8Database System Concepts - 5 th Edition, Oct 5, 2006 Formal Definition A basic expression in the relational algebra consists of either one of the following: A relation in the database A constant relation Let E 1 and E 2 be relational-algebra expressions; the following are all relational-algebra expressions: E 1  E 2 E 1 – E 2 E 1 x E 2  p (E 1 ), P is a predicate on attributes in E 1  s (E 1 ), S is a list consisting of some of the attributes in E 1  x (E 1 ), x is the new name for the result of E 1

©Silberschatz, Korth and Sudarshan2.9Database System Concepts - 5 th Edition, Oct 5, 2006 Additional Operations We define additional operations that do not add any power to the relational algebra, but that simplify common queries. Set intersection Natural join Division Assignment

©Silberschatz, Korth and Sudarshan2.10Database System Concepts - 5 th Edition, Oct 5, 2006 Set-Intersection Operation Notation: r  s Defined as: r  s = { t | t  r and t  s } Assume: r, s have the same arity attributes of r and s are compatible Note: r  s = r – (r – s)

©Silberschatz, Korth and Sudarshan2.11Database System Concepts - 5 th Edition, Oct 5, 2006 Set-Intersection Operation – Example Relation r, s: r  s A B   2323 rs  2

©Silberschatz, Korth and Sudarshan2.12Database System Concepts - 5 th Edition, Oct 5, 2006 Example Query Find the names of all customers who have a loan and an account at the bank.  customer_name (borrower)   customer_name (depositor)

©Silberschatz, Korth and Sudarshan2.13Database System Concepts - 5 th Edition, Oct 5, 2006 Notation: r s Natural-Join Operation Let r and s be relations on schemas R and S respectively. Then, r s is a relation on schema R  S obtained as follows: Consider each pair of tuples t r from r and t s from s. If t r and t s have the same value on each of the attributes in R  S, add a tuple t to the result, where  t has the same value as t r on r  t has the same value as t s on s Example: R = (A, B, C, D) S = (E, B, D) Result schema = (A, B, C, D, E) r s is defined as:  r.A, r.B, r.C, r.D, s.E (  r.B = s.B  r.D = s.D (r x s))

©Silberschatz, Korth and Sudarshan2.14Database System Concepts - 5 th Edition, Oct 5, 2006 Natural Join Operation – Example Relations r, s: AB  CD  aababaabab B D aaabbaaabb E  r AB  CD  aaaabaaaab E  s r s

©Silberschatz, Korth and Sudarshan2.15Database System Concepts - 5 th Edition, Oct 5, 2006 Example Query Find the name and loan amount of all customers who have a loan at the bank.  customer_name, amount (borrower loan)  customer. customer_name (  customer_city = “Jessore ” (customer depositor account )) Find the names of all customers who have an account in the bank and who live in Jessore Natural Join is associative

©Silberschatz, Korth and Sudarshan2.16Database System Concepts - 5 th Edition, Oct 5, 2006 Example Query Find the names of all customers who have a loan and an account at the bank.  customer_name (borrower)   customer_name (depositor)  customer_name (borrower depositor) When R S =R X S ? If R  S= φ

©Silberschatz, Korth and Sudarshan2.17Database System Concepts - 5 th Edition, Oct 5, 2006 Summary

©Silberschatz, Korth and Sudarshan2.18Database System Concepts - 5 th Edition, Oct 5, 2006 Division Operation Notation: Suited to queries that include the phrase “for all”. Let r and s be relations on schemas R and S respectively where R = (A 1, …, A m, B 1, …, B n ) S = (B 1, …, B n ) The result of r  s is a relation on schema R – S = (A 1, …, A m ) r  s = { t | t   R-S (r)   u  s ( tu  r ) } Where tu means the concatenation of tuples t and u to produce a single tuple r  s

©Silberschatz, Korth and Sudarshan2.19Database System Concepts - 5 th Edition, Oct 5, 2006 Division Operation – Example Relations r, s: r  s: B A  1212 AB  r s

©Silberschatz, Korth and Sudarshan2.20Database System Concepts - 5 th Edition, Oct 5, 2006 Another Division Example AB  aaaaaaaaaaaaaaaa CD  aabababbaabababb E Relations r, s: r  s: D abab E 1111 AB  aaaa C  r s

©Silberschatz, Korth and Sudarshan2.21Database System Concepts - 5 th Edition, Oct 5, 2006 Find all customers who have an account at all branches located in Brooklyn city. Bank Example Queries  customer_name, branch_name (depositor account)   branch_name (  branch_city = “Brooklyn” (branch))

©Silberschatz, Korth and Sudarshan2.22Database System Concepts - 5 th Edition, Oct 5, 2006 Assignment Operation The assignment operation (  ) provides a convenient way to express complex queries. Write query as a sequential program consisting of  a series of assignments  followed by an expression whose value is displayed as a result of the query. Assignment must always be made to a temporary relation variable. Example: The result to the right of the  is assigned to the relation variable on the left of the . May use variable in subsequent expressions. r 1    branch_city = “dhaka” (account branch ) r 2   account_number (r 1 )