©Silberschatz, Korth and Sudarshan3.1Database System Concepts Extended Relational-Algebra-Operations Generalized Projection Aggregate Functions Outer Join.

Slides:



Advertisements
Similar presentations
Chapter 3: Relational Model  Structure of Relational Databases  Normal forms (chap. 7)  Reduction of an E-R Schema to Relational (Sect. 2.9)  Relational.
Advertisements

Ver 1,12/09/2012Kode :CCs 111,sistem basisdataFASILKOM Chapter 2: Relational Model Database System Concepts, 5th Ed. ©Silberschatz, Korth and Sudarshan.
©Silberschatz, Korth and Sudarshan3.1Database System Concepts Chapter 3: Relational Model Structure of Relational Databases Relational Algebra Tuple Relational.
E-R Diagram for a Banking Enterprise
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 Sudarshan4.1Database System Concepts Ordering the Display of Tuples List in alphabetic order the names of all customers having.
©Silberschatz, Korth and Sudarshan3.1Database System Concepts Extended Relational-Algebra-Operations Generalized Projection Outer Join Aggregate Functions.
©Silberschatz, Korth and Sudarshan4.1Database System Concepts Chapter 4: SQL Basic Structure Set Operations Aggregate Functions Null Values Nested Subqueries.
©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.
Slides adapted from A. Silberschatz et al. Database System Concepts, 5th Ed. SQL - part 2 - Database Management Systems I Alex Coman, Winter 2006.
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 Sudarshan4.1Database System Concepts Chapter 4: SQL Basic Structure Set Operations Aggregate Functions Null Values Nested Subqueries.
©Silberschatz, Korth and Sudarshan4.1Database System Concepts Null Values It is possible for tuples to have a null value for some of their attributes The.
©Silberschatz, Korth and Sudarshan5.1Database System Concepts Chapter 5: Other Relational Languages Query-by-Example (QBE) Datalog.
©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.
Lecture 6 Structured Query Language SQL Lecture 6 Structured Query Language SQL Instructor: Haya Sammaneh.
Structured Query Language 2 Presented by: Annisa, M.Kom. Source: Database System Concepts 5 th edition.
©Silberschatz, Korth and Sudarshan2.1Database System Concepts Chapter 2: Relational Model Structure of Relational Databases Relational Algebra.
©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, 5 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 2: Relational.
Computing & Information Sciences Kansas State University Monday, 04 Feb 2008CIS 560: Database System Concepts Lecture 6 of 42 Monday, 04 February 2008.
©Silberschatz, Korth and Sudarshan5.1Database System Concepts Chapter 5: Other Relational Languages Query-by-Example (QBE)
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.
Computing & Information Sciences Kansas State University Monday, 08 Sep 2008CIS 560: Database System Concepts Lecture 5 of 42 Monday, 08 September 2008.
Relational Model By Dr.S.Sridhar, Ph.D.(JNUD), RACI(Paris, NICE), RMR(USA), RZFM(Germany) DIRECTOR ARUNAI ENGINEERING COLLEGE TIRUVANNAMALAI.
Yufis Azhar – Teknik Informatika – UMM.  Aggregation function takes a collection of values (of a single attribute) and returns a single value as a result.
Advanced Database Systems By- Jesmin Akhter Assistant Professor, IIT, Jahangirnagar University.
©Silberschatz, Korth and Sudarshan5.1Database System Concepts Chapter 5: Other Relational Query Languages Tuple Relational Calculus Domain Relational Calculus.
ICOM 5016 – Introduction to Database Systems Lecture 8 Dr. Manuel Rodriguez Department of Electrical and Computer Engineering University of Puerto Rico,
©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.
IS 230Lecture 6Slide 1 Lecture 7 Advanced SQL Introduction to Database Systems IS 230 This is the instructor’s notes and student has to read the textbook.
©Silberschatz, Korth and Sudarshan2.1Database System Concepts - 5 th Edition, Oct 5, 2006 Example.
©Silberschatz, Korth and Sudarshan2.1Database System Concepts Chapter 2: Relational Model Structure of Relational Databases Relational Algebra.
Chapter 2: Relational Model. 2.2Unite International CollegeDatabase Management Systems Chapter 2: Relational Model Structure of Relational Databases Fundamental.
Chapter 4: SQL Complex Queries Complex Queries Views Views Modification of the Database Modification of the Database Joined Relations Joined Relations.
Database System Concepts, 5 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 2: Relational.
Computing & Information Sciences Kansas State University Friday, 08 Sep 2006CIS 560: Database System Concepts Lecture 07 of 42 Tuesday, 30 January 2007.
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 Sudarshan3.1Database System Concepts Week 3: Relational Model Structure of Relational Databases Relational Algebra Extended Relational-Algebra-Operations.
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
©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 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
Aljabar Relasi.
Midlands State University Topic: Relational DB Model
Temple University – CIS Dept. CIS661– Principles of Database Systems
Relational Model By Dr.S.Sridhar, Ph.D.(JNUD), RACI(Paris, NICE), RMR(USA), RZFM(Germany)
Chapter 3: Relational Model III
Chapter 2: Relational Model
Lecture 4 of 42 Relational Joins Wednesday, 30 January 2008
CS 405G: Introduction to Database Systems
Presentation transcript:

©Silberschatz, Korth and Sudarshan3.1Database System Concepts Extended Relational-Algebra-Operations Generalized Projection Aggregate Functions Outer Join

©Silberschatz, Korth and Sudarshan3.2Database System Concepts Generalized Projection Extends the projection operation by allowing arithmetic functions to be used in the projection list.  F1, F2, …, Fn (E) E is any relational-algebra expression Each of F 1, F 2, …, F n are are arithmetic expressions involving constants and attributes in the schema of E. Given relation credit-info(customer-name, limit, credit-balance), find how much more each person can spend:  customer-name, limit – credit-balance (credit-info)

©Silberschatz, Korth and Sudarshan3.3Database System Concepts Aggregate Functions and Operations Aggregation function takes a collection of values and returns a single value as a result. avg: average value min: minimum value max: maximum value sum: sum of values count: number of values Aggregate operation in relational algebra G 1, G 2, …, G n g F 1 ( A 1), F 2 ( A 2),…, F n ( A n) (E)  E is any relational-algebra expression  G 1, G 2 …, G n is a list of attributes on which to group (can be empty)  Each F i is an aggregate function  Each A i is an attribute name

©Silberschatz, Korth and Sudarshan3.4Database System Concepts Example 1 Relation r: AB   C g sum(c) (r) sum-C 27

©Silberschatz, Korth and Sudarshan3.5Database System Concepts Example 2 Relation account grouped by branch-name: branch-name g sum(balance) (account) branch-nameaccount-numberbalance Perryridge Brighton Redwood A-102 A-201 A-217 A-215 A branch-namebalance Perryridge Brighton Redwood

©Silberschatz, Korth and Sudarshan3.6Database System Concepts Aggregate Functions (Cont.) Result of aggregation does not have a name  Can use rename operation to give it a name  For convenience, we permit renaming as part of aggregate operation branch-name g sum(balance) as sum-balance (account)

©Silberschatz, Korth and Sudarshan3.7Database System Concepts Outer Join An extension of the join operation that avoids loss of information. Computes the join and then adds tuples from one relation that does not match tuples in the other relation to the result of the join. Uses null values  null signifies that the value is unknown or does not exist

©Silberschatz, Korth and Sudarshan3.8Database System Concepts Example Relation loan loan-numberamount L-170 L-230 L Relation borrower customer-nameloan-number Jones Smith Hayes L-170 L-230 L-155 branch-name Downtown Redwood Perryridge

©Silberschatz, Korth and Sudarshan3.9Database System Concepts Example (Cont.) Inner Join loan Borrower loan borrower Left Outer Join loan-numberamount L-170 L customer-name Jones Smith branch-name Downtown Redwood loan-numberamount L-170 L-230 L customer-name Jones Smith null branch-name Downtown Redwood Perryridge

©Silberschatz, Korth and Sudarshan3.10Database System Concepts Example (Cont.) Right Outer Join loan borrower loan-numberamount L-170 L-230 L null customer-name Jones Smith Hayes loan-numberamount L-170 L-230 L-260 L null customer-name Jones Smith null Hayes loan borrower Full Outer Join branch-name Downtown Redwood null branch-name Downtown Redwood Perryridge null

©Silberschatz, Korth and Sudarshan3.11Database System Concepts 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  Is an arbitrary decision. Could have returned null as result instead.  We follow the semantics of SQL in its handling of null values For duplicate elimination and grouping, null is treated like any other value, and two nulls are assumed to be the same  Alternative: assume each null is different from each other  Both are arbitrary decisions, so we simply follow SQL

©Silberschatz, Korth and Sudarshan3.12Database System Concepts Null Values Comparisons with null values return the special truth value unknown  If false was used instead of unknown, then not (A = 5 Three-valued logic using the truth value unknown:  OR: (unknown or true) = true, (unknown or false) = unknown (unknown or unknown) = unknown  AND: (true and unknown) = unknown, (false and unknown) = false, (unknown and unknown) = unknown  NOT: (not unknown) = unknown  In SQL “P is unknown” evaluates to true if predicate P evaluates to unknown Result of select predicate is treated as false if it evaluates to unknown

©Silberschatz, Korth and Sudarshan3.13Database System Concepts 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.

©Silberschatz, Korth and Sudarshan3.14Database System Concepts 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.

©Silberschatz, Korth and Sudarshan3.15Database System Concepts Deletion Examples Delete all account records in the Perryridge branch. account  account –  branch-name = “Perryridge” (account) Delete all loan records with amount in the range of 0 to 50 loan  loan –   amount  0  and amount  50 (loan) Delete all accounts at branches located in Needham. r 1    branch-city = “Needham” (account branch) r 2   branch-name, account-number, balance (r 1 ) r 3   customer-name, account-number (r 2 depositor) account  account – r 2 depositor  depositor – r 3

©Silberschatz, Korth and Sudarshan3.16Database System Concepts 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.

©Silberschatz, Korth and Sudarshan3.17Database System Concepts Insertion Examples Insert information in the database specifying that Smith has $1200 in account A-973 at the Perryridge branch. account  account  {(“Perryridge”, A-973, 1200)} depositor  depositor  {(“Smith”, A-973)} 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. r 1  (  branch-name = “Perryridge” (borrower loan)) account  account   branch-name, account-number,200 (r 1 ) depositor  depositor   customer-name, loan-number,(r 1 )

©Silberschatz, Korth and Sudarshan3.18Database System Concepts Updating A mechanism to change a value in a tuple without charging all values in the tuple Use the generalized projection operator to do this task r   F1, F2, …, FI, (r) Each F, is either the ith attribute of r, if the ith 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

©Silberschatz, Korth and Sudarshan3.19Database System Concepts Update Examples Make interest payments by increasing all balances by 5 percent. account   AN, BN, BAL * 1.05 (account) where AN, BN and BAL stand for account-number, branch-name and balance, respectively. Pay all accounts with balances over $10,000 6 percent interest and pay all others 5 percent account   AN, BN, BAL * 1.06 (  BAL  (account))   AN, BN, BAL * 1.05 (  BAL  (account))

©Silberschatz, Korth and Sudarshan3.20Database System Concepts Views Any relation that is not of the conceptual model but is made visible to a user as a “virtual relation” is called a view. A view is defined using the create view statement which has the form create view v as where is any legal relational algebra query expression. The view name is represented by v. Once a view is defined, the view name can be used to refer to the virtual relation that the view generates.

©Silberschatz, Korth and Sudarshan3.21Database System Concepts Examples Consider the view (named all-customer) consisting of branches and their customers. create view all-customer as  branch-name, customer-name (depositor account)   branch-name, customer-name (borrower loan) We can find all customers of the Perryridge branch by writing:  branch-name (  branch-name = “Perryridge” (all-customer))

©Silberschatz, Korth and Sudarshan3.22Database System Concepts Updates Through View Database modifications expressed as views must be translated to modifications of the actual relations in the database. Consider the person who needs to see all loan data in the loan relation except amount. The view given to the person, branch- loan, is defined as: create view branch-loan as  branch-name, loan-number (loan) Since we allow a view name to appear wherever a relation name is allowed, the person may write: branch-loan  branch-loan  {(“Perryridge”, L-37)}

©Silberschatz, Korth and Sudarshan3.23Database System Concepts Updates Through Views (Cont.) The previous insertion must be represented by an insertion into the actual relation loan from which the view branch-loan is constructed. An insertion into loan requires a value for amount. The insertion can be dealt with by either.  rejecting the insertion and returning an error message to the user.  inserting a tuple (“L-37”, “Perryridge”, null) into the loan relation Some updates through views are impossible to translate into database relation updates  create view v as  branch-name = “Perryridge” (account)) v  v  (L-99, Downtown, 23) Others cannot be translated uniquely  all-customer  all-customer  (Perryridge, John)  Have to choose loan or account, and create a new loan/account number!

©Silberschatz, Korth and Sudarshan3.24Database System Concepts Views Defined Using Other Views One view may be used in the expression defining another view A view relation v 1 is said to depend directly on a view relation v 2 if v 2 is used in the expression defining v 1 A view relation v 1 is said to depend on view relation v 2 if either v 1 depends directly to v 2 or there is a path of dependencies from v 1 to v 2 A view relation v is said to be recursive if it depends on itself.