Query-by-Example (QBE) Presented by: Wong, Lok Man CS 157A Dr. Sin Min Lee.

Slides:



Advertisements
Similar presentations
Chapter 5: Other Relational Languages
Advertisements

Chapter 5: Other Relational Languages
©Silberschatz, Korth and Sudarshan5.1Database System Concepts Chapter 5: Other Relational Languages Query-by-Example (QBE) Datalog.
Ver 1,12/09/2012Kode :CCs 111,Sistem basis DataFASILKOM Chapter 3: SQL Bambang Irawan Database System Concepts, 5th Ed. ©Silberschatz, Korth and Sudarshan.
Ver 1,12/09/2012Kode :CCs 111,Sistem basis DataFASILKOM Chapter 5: Other Relational Languages Database System Concepts, 5th Ed. ©Silberschatz, Korth and.
E-R Diagram for a Banking Enterprise
Domain Relational Calculus and Query-by-Example CS157a John Eagle.
Chapter 2 Relational Model (part II) Hankz Hankui Zhuo
SQL Sangeeta Devadiga CS157A, Fall Outline Background Data Definition Basic Structure Set Operation.
©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.
Database System Concepts, 5th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 3: SQL.
©Silberschatz, Korth and Sudarshan4.1Database System Concepts Chapter 4: SQL Basic Structure Set Operations Aggregate Functions Null Values Nested Subqueries.
SQL Structured Query Language Meizhen Huang. Content (4.1 – 4.4) Background Parts of SQL Basic Structure Set Operations Aggregate Functions.
Temple University – CIS Dept. CIS331– Principles of Database Systems V. Megalooikonomou Query by example (based on notes by Silberchatz,Korth, and Sudarshan.
©Silberschatz, Korth and Sudarshan4.1Database System Concepts Modification of the Database – Deletion Delete all account records at the Perryridge branch.
SQL Neyha Amar CS 157A, Fall Inserting The insert statement is used to add a row of data into a table Strings should be enclosed in single quotes,
SQL SQL stands for Structured Query Language SQL allows you to access a database SQL is an ANSI standard computer language SQL can execute queries against.
Chapter 5 Other Relational Languages By Cui, Can B.
Slides adapted from A. Silberschatz et al. Database System Concepts, 5th Ed. SQL - part 2 - Database Management Systems I Alex Coman, Winter 2006.
MySQL Tutorial (2) Introduction to Database. Banking Example branch (branch-name, branch-city, assets) customer (customer-name, customer-street, customer-city)
Database System Concepts, 5th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 5: Other Relational.
CIS552SQL1 Data Definition Language Insertions Basic Query Structure Set Operations Aggregate Functions Null Values Nested Subqueries Derived Relations.
Chapter 3: SQL Data Definition Language Data Definition Language Basic Structure of SQL Basic Structure of SQL Set Operations Set Operations Aggregate.
Database System Concepts, 5th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 3: SQL.
©Silberschatz, Korth and Sudarshan4.1Database System Concepts Chapter 4: SQL Basic Structure Set Operations Aggregate Functions Null Values Nested Subqueries.
SQL. Basic Structure SQL is based on set and relational operations with certain modifications and enhancements A typical SQL query has the form: select.
©Silberschatz, Korth and Sudarshan5.1Database System Concepts Chapter 5: Other Relational Languages Query-by-Example (QBE) Datalog.
Lecture 6 Structured Query Language SQL Lecture 6 Structured Query Language SQL Instructor: Haya Sammaneh.
3.1 Chapter 3: SQL Schema used in examples p (omit 3.8.2, , 3.11)
Basic Structure Given sets A 1, A 2,..., A n a relation r is a subset of A 1 x A 2 x... x A n Thus a relation is a set of n-tuples (a 1, a 2,..., a n )
Chapter 5: Other Relational Languages. 5.2 Chapter 5: Other Relational Languages Tuple Relational Calculus Domain Relational Calculus Query-by-Example.
Structured Query Language 2 Presented by: Annisa, M.Kom. Source: Database System Concepts 5 th edition.
©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.
©Silberschatz, Korth and Sudarshan5.1Database System Concepts Chapter 5: Other Relational Languages Query-by-Example (QBE)
Computing & Information Sciences Kansas State University Tuesday, 13 Feb 2007CIS 560: Database System Concepts Lecture 12 of 42 Tuesday, 13 February 2007.
Computing & Information Sciences Kansas State University Thursday, 08 Feb 2007CIS 560: Database System Concepts Lecture 11 of 42 Thursday, 08 February.
Computing & Information Sciences Kansas State University Monday, 08 Sep 2008CIS 560: Database System Concepts Lecture 5 of 42 Monday, 08 September 2008.
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.
Chapter 8: SQL. Data Definition Modification of the Database Basic Query Structure Aggregate Functions.
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.
Computing & Information Sciences Kansas State University Monday, 17 Sep 2007CIS 560: Database System Concepts Lecture 12 of 42 Monday, 18 February 2008.
Source: Database System Concepts, Silberschatz etc Edited: Wei-Pang Yang, IM.NDHU, Introduction to Database CHAPTER 5 Other Relational Languages.
Chapter 4: SQL Complex Queries Complex Queries Views Views Modification of the Database Modification of the Database Joined Relations Joined Relations.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Appendix C: Other Relational.
Database System Concepts, 5th Ed. Bin Mu at Tongji University Chapter 5: Other Relational Languages.
©Silberschatz, Korth and Sudarshan3.1Database System Concepts Extended Relational-Algebra-Operations Generalized Projection Aggregate Functions Outer Join.
Computing & Information Sciences Kansas State University Friday, 08 Sep 2006CIS 560: Database System Concepts Lecture 07 of 42 Tuesday, 30 January 2007.
Computing & Information Sciences Kansas State University Wednesday, 17 Sep 2008CIS 560: Database System Concepts Lecture 9 of 42 Wednesday, 18 September.
©Silberschatz, Korth and Sudarshan5.1Database System Concepts Chapter 5: Other Relational Languages Query-by-Example (QBE) Datalog.
Database System Concepts, 5th Ed. ©Silberschatz, Korth and Sudarshan Chapter 5: Other Relational Languages.
MySQL Tutorial Introduction to Database. Introduction of MySQL  MySQL is an SQL (Structured Query Language) based relational database management system.
Relational Algebra HW2 Turn in as a hardcopy at the start of next class period. You may work this assignment in groups.
Computing & Information Sciences Kansas State University Tuesday. 13 Feb 2007CIS 560: Database System Concepts Lecture 13 of 42 Tuesday, 13 February 2007.
©Silberschatz, Korth and Sudarshan4.1Database System Concepts Chapter 4: SQL Basic Structure Set Operations Aggregate Functions Null Values Nested Subqueries.
Database System Concepts, 5th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 5: Other Relational.
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.
CS 480: Database Systems Lecture 16 February 20,2013.
CS 480: Database Systems Lecture 17 February 22, 2013.
Relational Model By Dr.S.Sridhar, Ph.D.(JNUD), RACI(Paris, NICE), RMR(USA), RZFM(Germany)
Chapter 3: Relational Model III
Structured Query Language (SQL)
Chapter 3: SQL.
Chapter 3: SQL.
Chapter 5: Other Relational Languages
Instructor: Mohamed Eltabakh
Appendix C: Other Relational Languages
CS 405G: Introduction to Database Systems
Presentation transcript:

Query-by-Example (QBE) Presented by: Wong, Lok Man CS 157A Dr. Sin Min Lee

History of QBE History: QBE is the name of both a data-manipulation language and an early database system that included this language QBE was developed at IBM’s T.J. Watson Research Center (1970’s)

Content QBE Basic Structure Queries on One Relation Queries on Several Relations Condition Box Result Relation Ordering of the Display of Tuples Aggregate Operations Modification of Database QBE in Microsoft Access

Basic Structure QBE has two dimensional syntax: 1. Queries look like tables 2. QBE queries are expressed “by example” Non-procedural Queries are expressed using skeleton tables branchBranch-nameBranch-cityassets

Basic Structure User selects skeletons needed User fills in the skeletons with example row Example row consists of constants & example elements, which are domain variables Constants appear without any qualification QBE uses an underscore character “_” before domain variables, as in “_x”

Queries on One Relation Ex: Find all loan numbers at the Perryridge branch Bring up the skeleton of the loan relation P. – before the variable to display the value X – a variable Perryridge – branch-name Loanloan-numberbranch-nameamount P._xPerryridge

Queries on One Relation (cont.) Ex: Suppress duplicate elimination - insert “ALL” Ex: display entire loan relation – place single P. loanloan-numberbranch-nameamount P.ALLPerryridge loanloan-numberbranch-nameamount P.

Queries on One Relation (cont.) Ex: Find loan numbers of all loans with amount more than $700. Use arithmetic operations (=,, ¬) With no variable, displays all attributes Ex: Find names of all branches not in Brooklyn loanloan-numberbranch-nameamount P.>700 branchbranch-namebranch-cityassets P.¬Brooklyn

Queries on One Relation (cont.) Ex: Find the loan numbers of all loans made jointly to Smith and Jones. Only one P. is needed. Ex: Find all customers who live in the same city as Jones customercustomer-namecustomer-streetcustomer-city P._x_y Jones_y borrowerCustomer-nameloan-number “Smith”P._x “Jones”_x

Queries on Several Relations QBE allows queries to span several different relations The connection among the various relations are achieved through variables that force certain tuples to have the same value on certain attributes

Queries on Several Relation (cont.) Ex: Find the names of all the customers that have a loan from the Perryridge branch loanloan-numberbranch-nameamount _XPerryridge borrowercustomer-nameloan-number P._y_X

Queries on Several Relation (Cont.) Ex: Find the names of all customer with both and an account and a loan at the bank The “¬” symbol represents “there does not exist”. A “¬” under an attribute name stands for “not equal”. depositorcustomer-nameaccount-number P._x borrowercustomer-nameloan-number ¬ _x

Queries on Several Relation (Cont.) Ex: Display all customer-name values that appear in at least two tuples, with the second tuple having an account-number different from the first. depositorcustomer-nameaccount-number P._x_y _x ¬ _y

Condition Box QBE includes a condition box feature that allow the expression of general constraints over any of the domain variables. Logical operators in words and and or, or as symbols “&” and “|”, appear in a condition box Ex: Find the loan numbers of all loans made to Smith, to Jones, or both borrowercustomer-nameLoan-number _nP._x condition _n = Smith or _n = Jones

Condition Box (Cont.) Ex: Find all branches that have assets greater than those of at least one branch located in Brooklyn branchbranch-namebranch-cityassets P._x_y Brooklyn_z conditions _y > _z

Condition Box (Cont.) Ex: Find all account numbers of account with a balance between $1000 and $1500, but not exactly $1255 accountaccount-numberbranch-namebalance P._y_x conditions _x = ( > 999 and < 1501 and ¬ 1255)

Result Relation If the result of a query includes attributes from several relation schemas, we can declare a temporary result relation that includes all the attributes of the result. Ex: Create a skeleton table, called result, with attributes customer-name, account-number, and balance, at the Perryridge branch. (Two Steps) 1. accountaccount-numberbranch-namebalance _yPerryridge_z depositorcustomer-nameaccount-number _x_y

Result Relation (Cont.) Once the new skeleton table is created, write the query. 2. resultcustomer- name account- number balance resultcustomer- name account- number balance P._x_y_z

Ordering of the Display Tuples To gain control over the order in which tuples in a relation are displayed, indicate AO (ascending order) or Do (descending order). To specify the order in which the sorting should be carried, add an integer surrounded by parentheses after sort operator (AO(1) or DO(2)).

Ordering of the Display Tuples (Cont.) Ex: List all account numbers at the Downtown branch in ascending alphabetic order with their respective account balances in descending order. accountaccount-numberbranch-namebalance P.AO(1)DowntownP.DO(2)

Aggregate Operations Aggregate Operators include AVG, MIN, MAX, SUM, and CNT We must postfix these operators with “ALL.” to create a multiset on which the aggregate operation is evaluated Operator “UNQ.” is to specify that duplicates are to be eliminated To compute functions on groups of tuples, then use “G.”.

Aggregate Operations (Cont.) Ex: Find the total balance of all the accounts maintained at the Downtown branch Ex: Find the total number of customers who have an account at the bank accountaccount-numberbranch-namebalance DowntownP.SUM.ALL. depositorcustomer-nameaccount-number P.CNT.UNQ.

Aggregate Operations (Cont.) Ex: Find the average balance at each branch accountaccount-numberbranch-namebalance P.G.P.AVG.ALL._x

Ex: Find all customers who have accounts at each of the branches located in Brooklyn depositorcustomer-nameaccount-number P.G._X_y accountaccount-numberbranch-namebalance _y_z branchbranch-namebranch-cityassets _zBrooklyn _wBrooklyn conditions CNT.UNQ._z = CNT.UNQ._w

Modification of the Database Deletion, uses “D.” replacing “P.” Insertion, uses “I.” replacing “P.” Updates, uses “U.” replacing “P.”

Deletion Ex: Delete customer Roy Ex: Delete the branch-city value of the branch whose name is “San Jose” depositorcustomer-nameaccount-number D.Roy branchbranch-namebranch-cityassets San JoseD.

Deletion (Cont.) Ex: Delete all accounts at all branches located in Brooklyn depositorcustomer-nameaccount-number D._y branchbranch-namebranch-cityassets _xBrooklyn accountaccount-numberbranch-namebalance D._y_x

Insertion Ex: Insert the fact that account AM-8976 at the Downtown branch has a balance of $900. Ex: Insert information into the branch relation about a new branch with name “Capital”, city “Queens,” and asset “200,000” accountaccount-numberbranch-namebalance I.AM-8976Downtown900 branchbranch-namebranch-cityassets I.CapitalQueens200,000

Insertion (Cont.) Ex: Insert as a gift, for all loan customers of the Downtown branch, a new $300 savings account for every loan account that they have, with the loan number serving as the account number for the savings account.

Insertion (Cont.) accountaccount-numberbranch-namebalance I._xDowntown300 depositorcustomer-nameaccount-number I._y_x loanloan-numberbranch-nameamount _xDowntown borrowercustomer-nameLoan-number _y_x

Updates Ex: Update the asset value of the San Jose branch to $100,000,000. Ex: Update all balances with a 5% increase. Use “_x” to hold the old balances branchbranch-namebranch-cityassets San JoseU.100,000,000 accountaccount-numberbranch-namebalance U._x * 1.05

QBE in Microsoft Access Original QBE was designed for a text-based display environment Access QBE is a graphical display environment, called graphical query-by-example (GQBE) GQBE version attributes are written one below the other, instead of horizontally Instead of shared variable in QBE, GQBE uses lines to link attributes of two tables

QBE in Microsoft Access (Cont.) In GQBE links are automatically created, on the basis of the attribute name In GQBE attributes printed in a separate box is specified, called the design grid, instead of using “P.” for QBE.

THE END!!! THANKS FOR STAYING AWAKE! QUIZ TIME!!!