Download presentation
Presentation is loading. Please wait.
Published byLinda McKenzie Modified over 9 years ago
1
©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 of information. n Computes the join and then adds tuples form one relation that does not match tuples in the other relation to the result of the join. n Uses null values: l null signifies that the value is unknown or does not exist l All comparisons involving null are (roughly speaking) false by definition. We shall study precise meaning of comparisons with nulls later
2
©Silberschatz, Korth and Sudarshan2.2Database System Concepts - 5 th Edition, Oct 5, 2006 Outer Join – Example Relation loan Relation borrower customer_nameloan_number Jones Smith Hayes L-170 L-230 L-155 3000 4000 1700 loan_numberamount L-170 L-230 L-260 branch_name Downtown Redwood Perryridge
3
©Silberschatz, Korth and Sudarshan2.3Database System Concepts - 5 th Edition, Oct 5, 2006 Outer Join – Example Join loan borrower loan_numberamount L-170 L-230 3000 4000 customer_name Jones Smith branch_name Downtown Redwood Jones Smith null loan_numberamount L-170 L-230 L-260 3000 4000 1700 customer_namebranch_name Downtown Redwood Perryridge Left Outer Join loan borrower
4
©Silberschatz, Korth and Sudarshan2.4Database System Concepts - 5 th Edition, Oct 5, 2006 Outer Join – Example loan_numberamount L-170 L-230 L-155 3000 4000 null customer_name Jones Smith Hayes branch_name Downtown Redwood null loan_numberamount L-170 L-230 L-260 L-155 3000 4000 1700 null customer_name Jones Smith null Hayes branch_name Downtown Redwood Perryridge null Full Outer Join loan borrower Right Outer Join loan borrower
5
©Silberschatz, Korth and Sudarshan2.5Database System Concepts - 5 th Edition, Oct 5, 2006 Example
6
©Silberschatz, Korth and Sudarshan2.6Database System Concepts - 5 th Edition, Oct 5, 2006 Example
7
©Silberschatz, Korth and Sudarshan2.7Database System Concepts - 5 th Edition, Oct 5, 2006 Example
8
©Silberschatz, Korth and Sudarshan2.8Database System Concepts - 5 th Edition, Oct 5, 2006 Example
9
©Silberschatz, Korth and Sudarshan2.9Database System Concepts - 5 th Edition, Oct 5, 2006 Null Values It is possible for tuples to have a null value, denoted by null, for some of their attributes null signifies an unknown value or that a value does not exist. The result of any arithmetic expression involving null is null. Aggregate functions simply ignore null values (as in SQL) For duplicate elimination and grouping, null is treated like any other value, and two nulls are assumed to be the same (as in SQL)
10
©Silberschatz, Korth and Sudarshan2.10Database System Concepts - 5 th Edition, Oct 5, 2006 Null Values n Comparisons with null values return the special truth value: unknown n Three-valued logic using the truth value unknown: l OR: (unknown or true) = true, (unknown or false) = unknown (unknown or unknown) = unknown l AND: (true and unknown) = unknown, (false and unknown) = false, (unknown and unknown) = unknown l NOT: (not unknown) = unknown l In SQL “P is unknown” evaluates to true if predicate P evaluates to unknown n Result of select predicate is treated as false if it evaluates to unknown
11
©Silberschatz, Korth and Sudarshan2.11Database System Concepts - 5 th Edition, Oct 5, 2006 Modification of the Database The content of the database may be modified using the following operations: Deletion Insertion Updating All these operations are expressed using the assignment operator.
12
©Silberschatz, Korth and Sudarshan2.12Database System Concepts - 5 th Edition, Oct 5, 2006 Deletion A delete request is expressed similarly to a query, except instead of displaying tuples to the user, the selected tuples are removed from the database. Can delete only whole tuples; cannot delete values on only particular attributes A deletion is expressed in relational algebra by: r r – E where r is a relation and E is a relational algebra query.
13
©Silberschatz, Korth and Sudarshan2.13Database System Concepts - 5 th Edition, Oct 5, 2006 Deletion Examples Delete all account records in the Perryridge branch. Delete all accounts of Brighton branch. r 1 branch_city = “Brooklyn” (account branch ) r 2 account_number, branch_name, balance (r 1 ) r 3 customer_name, account_number (r 2 depositor) depositor depositor – r 3 account account – r 2 Delete all loan records with amount in the range of 0 to 50 loan loan – amount 0 Λ amount 50 (loan) account account – branch_name = “Perryridge” (account )
14
©Silberschatz, Korth and Sudarshan2.14Database System Concepts - 5 th Edition, Oct 5, 2006 Insertion To insert data into a relation, we either: specify a tuple to be inserted write a query whose result is a set of tuples to be inserted in relational algebra, an insertion is expressed by: r r E where r is a relation and E is a relational algebra expression. The insertion of a single tuple is expressed by letting E be a constant relation containing one tuple.
15
©Silberschatz, Korth and Sudarshan2.15Database System Concepts - 5 th Edition, Oct 5, 2006 Insertion Examples Insert information in the database specifying that Smith has $1200 in account A-973 at the Perryridge branch. Provide as a gift for all loan customers in the Perryridge branch, a $200 savings account. Let the loan number serve as the account number for the new savings account. account account {(“A-973”, “Perryridge”, 1200)} depositor depositor {(“Smith”, “A-973”)} r 1 ( branch_name = “Perryridge” (borrower loan)) r 2 loan_number, branch_name (r 1 ) account account (r 2 X {200}) depositor depositor customer_name, loan_number (r 1 )
16
©Silberschatz, Korth and Sudarshan2.16Database System Concepts - 5 th Edition, Oct 5, 2006 Updating A mechanism to change a value in a tuple without changing all values in the tuple Use the generalized projection operator to do this task Each F i is either the I th attribute of r, if the I th attribute is not updated, or, if the attribute is to be updated F i is an expression, involving only constants and the attributes of r, which gives the new value for the attribute
17
©Silberschatz, Korth and Sudarshan2.17Database System Concepts - 5 th Edition, Oct 5, 2006 Update Examples Make interest payments by increasing all balances by 5 percent. Pay all accounts with balances over $100, 6 percent interest and pay all others 5 percent account account_number, branch_name, balance * 1.06 ( Balance 100 (account )) account_number, branch_name, balance * 1.05 ( Balance 100 (account)) account account_number, branch_name, balance * 1.05 (account)
18
Database System Concepts, 5 th Ed. ©Silberschatz, Korth and Sudarshan See www.db-book.com for conditions on re-usewww.db-book.com End of Chapter 2
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.