1 Query-by-Example (QBE). 2 v A “GUI” for expressing queries. –Based on the Domain Relational Calulus (DRC)! –Actually invented before GUIs. –Very convenient.

Slides:



Advertisements
Similar presentations
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5 More SQL: Complex Queries, Triggers, Views, and Schema Modification.
Advertisements

Query-By-Example Ping Zhou Introduction to QBE Query-By-Example A high-level database management language Alternation to SQL for querying relational.
TURKISH STATISTICAL INSTITUTE 1 /34 SQL FUNDEMANTALS (Muscat, Oman)
1 Advanced SQL Queries. 2 Example Tables Used Reserves sidbidday /10/04 11/12/04 Sailors sidsnameratingage Dustin Lubber Rusty.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 SQL: Queries, Programming, Triggers Chapter 5 Modified by Donghui Zhang.
1 CHAPTER 4 RELATIONAL ALGEBRA AND CALCULUS. 2 Introduction - We discuss here two mathematical formalisms which can be used as the basis for stating and.
1 541: Relational Calculus. 2 Relational Calculus  Comes in two flavours: Tuple relational calculus (TRC) and Domain relational calculus (DRC).  Calculus.
The Relational Model. Introduction Introduced by Ted Codd at IBM Research in 1970 The relational model represents data in the form of table. Main concept.
Database Management System Module 3:. Complex Constraints In this we specify complex integrity constraints included in SQL. It relates to integrity constraints.
1 Lecture 11: Basic SQL, Integrity constraints
Database Management Systems 3ed, Online chapter, R. Ramakrishnan and J. Gehrke1 Query-by-Example (QBE) Online Chapter Example is the school of mankind,
5/15/2015Lecture 31 CS 222 Database Management System Spring Lecture 3 Korra Sathya Babu Department of Computer Science NIT Rourkela.
1 Relational Algebra & Calculus. 2 Relational Query Languages  Query languages: Allow manipulation and retrieval of data from a database.  Relational.
Database Management Systems, R. Ramakrishnan and J. Gehrke1 Query-by-Example (QBE) Chapter 6 Example is the school of mankind, and they will learn at no.
Domain Relational Calculus and Query-by-Example CS157a John Eagle.
FALL 2004CENG 351 File Structures and Data Management1 SQL: Structured Query Language Chapter 5.
Temple University – CIS Dept. CIS331– Principles of Database Systems V. Megalooikonomou Query by example (based on notes by Silberchatz,Korth, and Sudarshan.
1 Relational Model. 2 Relational Database: Definitions  Relational database: a set of relations  Relation: made up of 2 parts: – Instance : a table,
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 SQL: Queries, Constraints, Triggers Chapter 5.
Chapter 5 Other Relational Languages By Cui, Can B.
1 Views. 2 What are views good for? (1) Simplifying complex queries: We saw one example. Here is another that allows the user to "pretend" that there.
1 SQL: Structured Query Language Chapter 5. 2 SQL and Relational Calculus relationalcalculusAlthough relational algebra is useful in the analysis of query.
Database Systems More SQL Database Design -- More SQL1.
1 Relational Algebra and Calculus Yanlei Diao UMass Amherst Feb 1, 2007 Slides Courtesy of R. Ramakrishnan and J. Gehrke.
Rutgers University Relational Calculus 198:541 Rutgers University.
CSC343 – Introduction to Databases - A. Vaisman1 SQL: Queries, Programming, Triggers.
DATABASES AND SQL. Introduction Relation: Relation means table(data is arranged in rows and columns) Domain : A domain is a pool of values appearing in.
Relational DBs and SQL Designing Your Web Database (Ch. 8) → Creating and Working with a MySQL Database (Ch. 9, 10) 1.
©Silberschatz, Korth and Sudarshan5.1Database System Concepts Chapter 5: Other Relational Languages Query-by-Example (QBE) Datalog.
1 Relational Algebra and Calculus Chapter 4. 2 Relational Query Languages  Query languages: Allow manipulation and retrieval of data from a database.
CSE314 Database Systems More SQL: Complex Queries, Triggers, Views, and Schema Modification Doç. Dr. Mehmet Göktürk src: Elmasri & Navanthe 6E Pearson.
10/31/2012ISC239 Isabelle Bichindaritz1 SQL Graphical Queries Design Query By Example.
Analyzing Data For Effective Decision Making Chapter 3.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Relational Calculus Chapter 4, Section 4.3.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Appendix C Overview of the QBE (Query-By-Example) Language.
©Silberschatz, Korth and Sudarshan5.1Database System Concepts Chapter 5: Other Relational Languages Query-by-Example (QBE)
SQL Part I: Standard Queries. COMP-421: Database Systems - SQL Queries I 2 Example Instances sid sname rating age 22 debby debby lilly.
SQL: Queries, Programming, Triggers. Example Instances We will use these instances of the Sailors and Reserves relations in our examples. If the key for.
6 1 Lecture 8: Introduction to Structured Query Language (SQL) J. S. Chou, P.E., Ph.D.
1 Relational Algebra & Calculus Chapter 4, Part A (Relational Algebra)
1 Relational Algebra and Calculas Chapter 4, Part A.
Database Management COP4540, SCS, FIU Structured Query Language (Chapter 8)
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.
AL-MAAREFA COLLEGE FOR SCIENCE AND TECHNOLOGY INFO 232: DATABASE SYSTEMS CHAPTER 7 (Part II) INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL) Instructor.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 SQL: Queries, Constraints, Triggers Chapter 5.
CSC 411/511: DBMS Design Dr. Nan WangCSC411_L5_Relational Calculus 1 Relational Calculus Chapter 4 – Part B.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Database Management Systems Chapter 5 SQL.
1 SQL: The Query Language. 2 Example Instances R1 S1 S2 v We will use these instances of the Sailors and Reserves relations in our examples. v If the.
Database Management Systems, R. Ramakrishnan1 Relational Calculus Chapter 4, Part B.
Chapter 3 The Relational Model. Why Study the Relational Model? Most widely used model. Vendors: IBM, Informix, Microsoft, Oracle, Sybase, etc. “Legacy.
Concepts of Database Management, Fifth Edition Chapter 3: The Relational Model 2: SQL.
1 Relational Calculus ♦ Comes in two flavors: Tuple relational calculus (TRC) and Domain relational calculus (DRC). ♦ Calculus has variables, constants,
More SQL: Complex Queries, Triggers, Views, and Schema Modification
Relational Calculus Chapter 4, Section 4.3.
Relational Algebra & Calculus
More SQL: Complex Queries,
CS 480: Database Systems Lecture 17 February 22, 2013.
COP Introduction to Database Structures
Query-by-Example (QBE)
SQL: Advanced Options, Updates and Views Lecturer: Dr Pavle Mogin
Query By Example (QBE) Mallipeddi Venkata Harish Terence Gam Israel.
Chapter 4 Summary Query.
More SQL: Complex Queries, Triggers, Views, and Schema Modification
Access: SQL Participation Project
SQL: Structured Query Language
Contents Preface I Introduction Lesson Objectives I-2
Relational Algebra & Calculus
CS 405G: Introduction to Database Systems
Presentation transcript:

1 Query-by-Example (QBE)

2 v A “GUI” for expressing queries. –Based on the Domain Relational Calulus (DRC)! –Actually invented before GUIs. –Very convenient for simple queries. –Awkward for complex queries. v QBE an IBM trademark. –But has influenced many projects –Especially PC Databases: Paradox, Access, etc.

3 `Example Tables’ in QBE v Users specify a query by filling in example tables, or skeletons ; we will use these skeletons in our examples.

4 Basics v To print names and ages of all sailors: v Print all fields for sailors with rating > 8, in ascending order by ( rating, age ): v QBE puts unique new variables in blank columns. Above query in DRC (no ordering):

5 And/Or Queries v Names of sailors younger than 30 or older than 20: v Names of sailors younger than 30 and older than 20: v Names of sailors younger than 30 and rating > 4:

6 Duplicates v Single row with P: Duplicates not eliminated by default; can force elimination by using UNQ. v Multiple rows with P: Duplicates eliminated by default! Can avoid elimination by using ALL.

7 Join Queries v Names of sailors who’ve reserved a boat for 8/24/96 and are older than 25 (note that dates and strings with blanks/special chars are quoted): v Joins accomplished by repeating variables.

8 Join Queries (Contd.) v Colors of boats reserved by sailors who’ve reserved a boat for 8/24/96 and are older than 25 :

9 Join Queries (Contd.) v Names and ages of sailors who’ve reserved some boat that is also reserved by the sailor with sid = 22:

10 Unnamed Columns v Useful if we want to print the result of an expression, or print fields from 2 or more relations. –QBE allows P. to appear in at most one table!

11 “Negative Tables” v Can place a negation marker in the relation column: v Variables appearing in a negated table must also appear in a positive table!

12 Aggregates v QBE supports AVG, COUNT, MIN, MAX, SUM –None of these eliminate duplicates, except COUNT –Also have AVG.UNQ. etc. to force duplicate elimination v The columns with G. are the group-by fields; all tuples in a group have the same values in these fields. — The (optional) use of.AO orders the answers. — Every column with P. must include G. or an aggregate operator.

13 Conditions Box v Used to express conditions involving 2 or more columns, e.g., _R/_A > 0.2. v Can express a condition that involves a group, similar to the HAVING clause in SQL: v Express conditions involving AND and OR:

14 Find sailors who’ve reserved all boats v A division query; need aggregates (or update operations, as we will see later) to do this in QBE. v How can we modify this query to print the names of sailors who’ve reserved all boats?

15 Inserting Tuples v Single-tuple insertion: v Inserting multiple tuples ( rating is null in tuples inserted below):

16 Delete and Update v Delete all reservations for sailors with rating < 4 v Increment the age of the sailor with sid = 74

17 Restrictions on Update Commands v Cannot mix I., D. and U. in a single example table, or combine them with P. or G. v Cannot insert, update or modify tuples using values from fields of other tuples in the same table. Example of an update that violates this rule: Should we update every Joe’s age? Which John’s age should we use?

18 Find sailors who’ve reserved all boats (Again!) v We want to find sailors _Id such that there is no boat _B that is not reserved by _Id: v Illegal query! Variable _B does not appear in a positive row. In what order should the two negative rows be considered? (Meaning changes!)

19 A Solution Using Views v Find sailors who’ve not reserved some boat _B: v Next, find sailors not in this `bad’ set:

20 A Peek at MS Access

21 Summary v QBE is an elegant, user-friendly query language based on DRC. v It is quite expressive (relationally complete, if the update features are taken into account). v Simple queries are especially easy to write in QBE, and there is a minimum of syntax to learn. v Has influenced the graphical query facilities offered in many products, including Borland’s Paradox and Microsoft’s Access.