Chapter 2: Relational Model II Relational Algebra basics Relational Algebra basics.

Slides:



Advertisements
Similar presentations
Ver 1,12/09/2012Kode :CCs 111,sistem basisdataFASILKOM Chapter 2: Relational Model Database System Concepts, 5th Ed. ©Silberschatz, Korth and Sudarshan.
Advertisements

Relational Databases - Amit Bhawnani & Nimesh Shah.
CS4432: Database Systems II Query Operator & Algebraic Expressions 1.
©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 Extended.
©Silberschatz, Korth and Sudarshan3.1Database System Concepts Chapter 3: Relational Model Structure of Relational Databases Relational Algebra Tuple Relational.
Relational Algebra Lecture 2. Relational Model Basic Notions Fundamental Relational Algebra Operations Additional Relational Algebra Operations Extended.
SQL Structured Query Language Meizhen Huang. Content (4.1 – 4.4) Background Parts of SQL Basic Structure Set Operations Aggregate Functions.
©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.
Relational Algebra Lecture 2. Relational Model Basic Notions Fundamental Relational Algebra Operations Additional Relational Algebra Operations Extended.
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.
Relational Algebra. Relational Query Languages n Query = “retrieval program” n Language examples: ù Theoretical : 1. Relational Algebra 2. Relational.
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.
©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.
PMIT-6102 Advanced Database Systems By- Jesmin Akhter Assistant Professor, IIT, Jahangirnagar University.
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.
Relational Algebra Instructor: Mohamed Eltabakh 1.
Database System Concepts, 5 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 2: Relational.
Chapter 6: Formal Relational Query Languages. 6.2 Chapter 6: Formal Relational Query Languages Relational Algebra Tuple Relational Calculus Domain Relational.
1 The Relational Model By Elena Ciriani CS157A February 19, 2004 Professor Lee.
ICOM 5016 – Introduction to Database Systems Lecture 5b 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.
CIS552Relational Model1 Structure of Relational Database Relational Algebra Extended Relational-Algebra-Operations Modification of the Database.
CS 370 Database Systems Lecture 11 Relational Algebra.
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.
Relational Model By Dr.S.Sridhar, Ph.D.(JNUD), RACI(Paris, NICE), RMR(USA), RZFM(Germany) DIRECTOR ARUNAI ENGINEERING COLLEGE TIRUVANNAMALAI.
Database System Concepts, 5 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Relational Model.
©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.
Chapter 2: Relational Model. 2.2Unite International CollegeDatabase Management Systems Chapter 2: Relational Model Structure of Relational Databases Fundamental.
Computing & Information Sciences Kansas State University Friday, 26 Jan 2008CIS 560: Database System Concepts Lecture 2 of 42 Friday, 29 August 2008 William.
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.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Module A: Formal Relational.
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.
Relational Algebra HW2 Turn in as a hardcopy at the start of next class period. You may work this assignment in groups.
©Silberschatz, Korth and Sudarshan3.1Database System Concepts Week 3: Relational Model Structure of Relational Databases Relational Algebra Extended Relational-Algebra-Operations.
ICOM 5016 – Introduction to Database Systems Lecture 6 Dr. Manuel Rodriguez Department of Electrical and Computer Engineering University of Puerto Rico,
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.
Database System Concepts, 5 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 2: Relational.
IS 230Lecture 7Slide 1 Relational Algebra Lecture 8 Text Book – Chapter.
International Computer Institute, Izmir, Turkey Relational Model Asst.Prof.Dr.İlker Kocabaş UBİ502 at
Relational Algebra Instructor: Mohamed Eltabakh 1.
©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.
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.
International Computer Institute, Izmir, Turkey Relational Model Asst.Prof.Dr.İlker Kocabaş UBİ502 at
Midlands State University Topic: Relational DB Model
Chapter 6: Formal Relational Query Languages
Session 3 Welcome: To session 3-the second learning sequence
Instructor: Mohamed Eltabakh
Chapter 2: Relational Model
Chapter 6: Formal Relational Query Languages
Presentation transcript:

Chapter 2: Relational Model II Relational Algebra basics Relational Algebra basics

ER for Banking Enterprise

Schema Diagram for the Banking Enterprise

Query Languages Categories of languages Categories of languages procedural procedural non-procedural non-procedural “Pure” languages: “Pure” languages: Relational Algebra Relational Algebra Tuple Relational Calculus Tuple Relational Calculus Domain Relational Calculus Domain Relational Calculus Declarative languages: Declarative languages: SQL SQL

Relational Algebra Procedural language Procedural language Six basic operators Six basic operators Select Select  Projection  Projection  Union Union  set difference set difference – Cartesian product Cartesian product x Rename  Rename  The operators take one or more relations as inputs and give a new relation as a result. The operators take one or more relations as inputs and give a new relation as a result.

Select Operation – Example Relation r ABCD    A=B ^ D > 5 (r) ABCD  

Select Operation Notation:  p (r) Notation:  p (r) p is called the selection predicate p is called the selection predicate Defined as: Defined as:  p ( r) = {t | t  r and p(t)}  p ( r) = {t | t  r and p(t)} Where p is a formula in propositional calculus consisting of terms connected by :  (and),  (or),  (not) Each term is one of: op or op or where op is one of: =, , >, ., . <. 

Example of selection  branch-name=“Perryridge ” (account)  branch-name=“Perryridge ” (account) Selection gives a horizontal subset of a relation Selection gives a horizontal subset of a relation a subset of all the tuples (rows) of a relation a subset of all the tuples (rows) of a relation  branch-name=“Perryridge”(account)  branch-name=“Perryridge”(account) ? ? account

Project Operation – Example Relation r: Relation r: ABC  AC  = AC   A,C (r)  A,C (r)

Project Operation Notation:  A1, A2, …, Ak (r) Notation:  A1, A2, …, Ak (r) where A 1, A 2 are attribute names and r is a relation name. The result is defined as the relation of k columns obtained by erasing the columns that are not listed The result is defined as the relation of k columns obtained by erasing the columns that are not listed Duplicate rows removed from result, since relations are sets Duplicate rows removed from result, since relations are sets

Example of Projection To eliminate the branch-name attribute of account  account-number, balance (account) To eliminate the branch-name attribute of account  account-number, balance (account) Projection gives a vertical subset of a relation Projection gives a vertical subset of a relation a subset of all the columns of a relation a subset of all the columns of a relation  account-number, balance (account) ? account

Union Operation – Example Relations r, s: Relations r, s: r  s: AB  AB  2323 r s AB 

Union Operation Notation: r  s Notation: r  s Defined as: Defined as: r  s = {t | t  r or t  s} For r  s to be valid. For r  s to be valid. 1. r, s must have the same arity (same number of attributes) 2. The attribute domains must be compatible (e.g., 2nd column of r deals with the same type of values as does the 2nd column of s)

Example of Union Find all customers with either an account or a loan  customer-name (depositor)   customer-name (borrower) Find all customers with either an account or a loan  customer-name (depositor)   customer-name (borrower) depositor borrower  customer-name (depositor)  customer-name (borrower)  ? ? ?

Set Difference Operation – Example Relations r, s: Relations r, s: r – s : AB  AB  2323 r s AB  1111

Set Difference Operation Notation r – s Notation r – s Defined as: Defined as: r – s = {t | t  r and t  s} r – s = {t | t  r and t  s} Set differences must be taken between compatible relations. Set differences must be taken between compatible relations. r and s must have the same arity r and s must have the same arity attribute domains of r and s must be compatible attribute domains of r and s must be compatible

Example of Set Difference Find all customers with either an account or a loan  customer-name (depositor)   customer-name (borrower) Find all customers with either an account or a loan  customer-name (depositor)   customer-name (borrower) depositor borrower  customer-name (depositor)  customer-name (borrower) - ? ? ?

Cartesian-Product Operation-Example Relations r, s: r x s: AB  1212 AB  CD  E aabbaabbaabbaabb CD  E aabbaabb r s

Cartesian-Product Operation Notation r x s Notation r x s Defined as: Defined as: r x s = {t q | t  r and q  s} Assume that attributes of r(R) and s(S) are disjoint. (That is, R  S =  ). Assume that attributes of r(R) and s(S) are disjoint. (That is, R  S =  ). If attributes of r(R) and s(S) are not disjoint, then renaming must be used. If attributes of r(R) and s(S) are not disjoint, then renaming must be used.

the borrower relation

the loan relation

Result of borrower |X| loan

Cartesian-Product Operation Cartesian-Product itself is usually not so useful Cartesian-Product itself is usually not so useful It is often used as a “pre-processing” It is often used as a “pre-processing” Other operators such as selection and projection will follow Other operators such as selection and projection will follow

Composition of Operations Can build expressions using multiple operations Can build expressions using multiple operations Example:  A=C (r x s) Example:  A=C (r x s) r x s r x s  A=C (r x s)  A=C (r x s) AB  CD  E aabbaabbaabbaabb ABCDE   20 aabaab

Rename Operation Allows us to refer to a relation by more than one name. Allows us to refer to a relation by more than one name. Example:  x (E) Example:  x (E) returns the expression E under the name X If a relational-algebra expression E has arity n, then If a relational-algebra expression E has arity n, then  x (A1, A2, …, An) (E)  x (A1, A2, …, An) (E) returns the result of expression E under the name X, and with the attributes renamed to A 1, A2, …., An.

Rename Operation Example: Example:  downtown-account(account-number,branch- name,balance) (  branch-name=“Downtown” (account) account ?

Banking Example branch (branch-name, branch-city, assets) customer (customer-name, customer-street, customer-only) account (account-number, branch-name, balance) loan (loan-number, branch-name, amount) depositor (customer-name, account-number) borrower (customer-name, loan-number)

Example Queries Find all loans of over $1200 Find all loans of over $1200 Find the loan number for each loan of an amount greater than $1200  amount > 1200 (loan)  loan-number (  amount > 1200 (loan))

Example Queries Find the names of all customers who have a loan, an account, or both, from the bank Find the names of all customers who have a loan, an account, or both, from the bank n Find the names of all customers who have a loan and an account at bank.  customer-name (borrower)   customer-name (depositor)  customer-name (borrower)   customer-name (depositor)

Example Queries Find the names of all customers who have a loan at the Perryridge branch. Find the names of all customers who have a loan at the Perryridge branch. n Find the names of all customers who have a loan at the Perryridge branch but do not have an account at any branch of the bank.  customer-name (  branch-name = “Perryridge” (  borrower.loan-number = loan.loan-number ( borrower x loan ))) –  customer-name ( depositor )  customer-name (  branch-name=“Perryridge ” (  borrower.loan-number = loan.loan-number (borrower x loan)))

Example Queries Find the names of all customers who have a loan at the Perryridge branch. Find the names of all customers who have a loan at the Perryridge branch.  Query 2  customer-name (  loan.loan-number = borrower.loan-number ( (  branch-name = “Perryridge” (loan)) x borrower))  Query 1  customer-name (  branch-name = “Perryridge” (  borrower.loan-number = loan.loan-number (borrower x loan)))

Example Queries Find the largest account balance Rename account relation as d Rename account relation as d The query is: The query is:  balance (account) -  account.balance (  account.balance < d.balance (account x  d (account)))

branch branch-name assets branch

account-number branch-name balance account

customer-name account-number depositor

customer-name customer-street customer-city customer

customer-name loan-number borrower

loan-number branch-name amount loan

customer

branch

loan

account

borrower

depositor