Query-by-Example (QBE)

Slides:



Advertisements
Similar presentations
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.
Advertisements

Database Management System Module 3:. Complex Constraints In this we specify complex integrity constraints included in SQL. It relates to 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.
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.
Midterm Review Lecture 14b. 14 Lectures So Far 1.Introduction 2.The Relational Model 3.Disks and Files 4.Relational Algebra 5.File Org, Indexes 6.Relational.
Temple University – CIS Dept. CIS331– Principles of Database Systems V. Megalooikonomou Query by example (based on notes by Silberchatz,Korth, and Sudarshan.
Chapter 5 Other Relational Languages By Cui, Can B.
©Silberschatz, Korth and Sudarshan5.1Database System Concepts Chapter 5: Other Relational Languages Query-by-Example (QBE) Datalog.
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)
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.
1 Relational Calculus ♦ Comes in two flavors: Tuple relational calculus (TRC) and Domain relational calculus (DRC). ♦ Calculus has variables, constants,
Relational Algebra & Calculus
CF 1334 Sistem Basis Data (3 SKS)
Diskusi-08 Jelaskan dan berikan contoh penggunaan theta join, equijoin, natural join, outer join, dan semijoin The slides for this text are organized into.
Diskusi-5 Sebutkan perangkat (tools) yang berpotensi mendukung kebutuhan tugas-tugas manajerial (management work) Jelaskan enam karakteristik informasi.
MODELS OF DATABASE AND DATABASE DESIGN
Tree-Structured Indexes
Storage and Indexes Chapter 8 & 9
Diskusi-1 Bacalah materi chapter-01, lalu buatlah ringkasan yang berisi tentang : Definisi EUIS Siapa end user Dampak euis pada lingkungan kerja Perencanaan.
Latihan Answer the following questions using the relational schema from the Exercises at the end of Chapter 3: Create the Hotel table using the integrity.
Diskusi-16 Buatlah ringkasan tentang pertimbangan dalam desain yang ergonomis pada tiga perangkat utama komputer yaitu monitor, keyboard dan mouse (lihat.
Database Application Development
Permutations and Combinations
Hash-Based Indexes Chapter 11
Latihan Create a separate table with the same structure as the Booking table to hold archive records. Using the INSERT statement, copy the records from.
Tugas-05 a. Sebutkan primary key masing-masing tabel
Introduction to Query Optimization
Relational Algebra Chapter 4, Part A
The Entity-Relationship Model
Modeling Your Data Chapter 2 cs542
Translation of ER-diagram into Relational Schema
File Organizations Chapter 8 “How index-learning turns no student pale
COSC 6340 Projects & Homeworks Spring 2002
Query By Example (QBE) Mallipeddi Venkata Harish Terence Gam Israel.
SQL: Queries, Programming, Triggers
From ER to Relational Model
The Entity-Relationship Model
Database Application Development
External Sorting The slides for this text are organized into chapters. This lecture covers Chapter 11. Chapter 1: Introduction to Database Systems Chapter.
B+-Trees and Static Hashing
File Organizations and Indexing
File Organizations and Indexing
Tree-Structured Indexes
Team Project, Part II NOMO Auto, Part II IST 210 Section 4
Hash-Based Indexes Chapter 10
Selected Topics: External Sorting, Join Algorithms, …
SQL: The Query Language Part 1
Relational Algebra Chapter 4, Sections 4.1 – 4.2
B+Trees The slides for this text are organized into chapters. This lecture covers Chapter 9. Chapter 1: Introduction to Database Systems Chapter 2: The.
The Relational Model The slides for this text are organized into chapters. This lecture covers Chapter 3. Chapter 1: Introduction to Database Systems Chapter.
Tree-Structured Indexes
Database Management Systems CSE594
SQL: Structured Query Language
SQL: Queries, Programming, Triggers
Contents Preface I Introduction Lesson Objectives I-2
CS 186, Fall 2002, Lecture 8 R&G, Chapter 4
Evaluation of Relational Operations: Other Techniques
Distributed Databases
Introduction to Database Systems
Relational Query Optimization (this time we really mean it)
Chapter 11 Instructor: Xin Zhang
Tree-Structured Indexes
Relational Algebra & Calculus
File Organizations and Indexing
COSC 3480 Projects & Homeworks Fall 2003
Database Application Development
Relational Calculus Chapter 4, Part B
Presentation transcript:

Query-by-Example (QBE) Online Chapter The slides for this text are organized into chapters. This lecture covers Chapter 6. Chapter 1: Introduction to Database Systems Chapter 2: The Entity-Relationship Model Chapter 3: The Relational Model Chapter 4 (Part A): Relational Algebra Chapter 4 (Part B): Relational Calculus Chapter 5: SQL: Queries, Programming, Triggers Chapter 6: Query-by-Example (QBE) Chapter 7: Storing Data: Disks and Files Chapter 8: File Organizations and Indexing Chapter 9: Tree-Structured Indexing Chapter 10: Hash-Based Indexing Chapter 11: External Sorting Chapter 12 (Part A): Evaluation of Relational Operators Chapter 12 (Part B): Evaluation of Relational Operators: Other Techniques Chapter 13: Introduction to Query Optimization Chapter 14: A Typical Relational Optimizer Chapter 15: Schema Refinement and Normal Forms Chapter 16 (Part A): Physical Database Design Chapter 16 (Part B): Database Tuning Chapter 17: Security Chapter 18: Transaction Management Overview Chapter 19: Concurrency Control Chapter 20: Crash Recovery Chapter 21: Parallel and Distributed Databases Chapter 22: Internet Databases Chapter 23: Decision Support Chapter 24: Data Mining Chapter 25: Object-Database Systems Chapter 26: Spatial Data Management Chapter 27: Deductive Databases Chapter 28: Additional Topics Example is the school of mankind, and they will learn at no other. -- Edmund Burke (1729-1797) 1

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

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

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

And/Or Queries Names of sailors younger than 30 or older than 20: Note: MiniQBE uses a slightly different syntax! And/Or Queries Names of sailors younger than 30 or older than 20: Names of sailors younger than 30 and older than 20: Names of sailors younger than 30 and rating > 4: 5

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

Note: MiniQBE uses double quotes Join Queries 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): Note: MiniQBE uses double quotes Joins accomplished by repeating variables. 7

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

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

Unnamed Columns MiniQBE allows P. in multiple tables 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! 10

“Negative Tables” Can place a negation marker in the relation column: Note: MiniQBE uses NOT or ~. Variables appearing in a negated table must also appear in a positive table!

Aggregates QBE supports AVG, COUNT, MIN, MAX, SUM None of these eliminate duplicates, except COUNT Also have AVG.UNQ. etc. to force duplicate elimination 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 Used to express conditions involving 2 or more columns, e.g., _R/_A > 0.2. Can express a condition that involves a group, similar to the HAVING clause in SQL: Express conditions involving AND and OR: 14

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

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

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

Restrictions on Update Commands Cannot mix I., D. and U. in a single example table, or combine them with P. or G. 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!) We want to find sailors _Id such that there is no boat _B that is not reserved by _Id: 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 Find sailors who’ve not reserved some boat _B: Next, find sailors not in this `bad’ set: 20

A Peek at MS Access

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