Query-by-Example (QBE)



Similar documents
6 QUERY-BY-EXAMPLE (QBE)

SQL: Queries, Programming, Triggers

Example Instances. SQL: Queries, Programming, Triggers. Conceptual Evaluation Strategy. Basic SQL Query. A Note on Range Variables

SQL: Queries, Programming, Triggers

Chapter 5. SQL: Queries, Constraints, Triggers

Relational Algebra and SQL

COMP 5138 Relational Database Management Systems. Week 5 : Basic SQL. Today s Agenda. Overview. Basic SQL Queries. Joins Queries

Boats bid bname color 101 Interlake blue 102 Interlake red 103 Clipper green 104 Marine red. Figure 1: Instances of Sailors, Boats and Reserves

Chapter 5 More SQL: Complex Queries, Triggers, Views, and Schema Modification

Relational Algebra. Module 3, Lecture 1. Database Management Systems, R. Ramakrishnan 1

The Relational Model. Why Study the Relational Model? Relational Database: Definitions

Relational Database: Additional Operations on Relations; SQL

SQL - QUICK GUIDE. Allows users to access data in relational database management systems.

A basic create statement for a simple student table would look like the following.

Proposed solutions Project Assignment #1 (SQL)

IT2305 Database Systems I (Compulsory)

Relational Calculus. Module 3, Lecture 2. Database Management Systems, R. Ramakrishnan 1

The Relational Model. Why Study the Relational Model? Relational Database: Definitions. Chapter 3

INFO/CS 330: Applied Database Systems

Introduction to Microsoft Jet SQL

Using Multiple Operations. Implementing Table Operations Using Structured Query Language (SQL)

IENG2004 Industrial Database and Systems Design. Microsoft Access I. What is Microsoft Access? Architecture of Microsoft Access

Lesson 07: MS ACCESS - Handout. Introduction to database (30 mins)

The Relational Model. Why Study the Relational Model?

3.GETTING STARTED WITH ORACLE8i

Lecture 6. SQL, Logical DB Design

Creating QBE Queries in Microsoft SQL Server

Database Security. Chapter 21

The Relational Model. Ramakrishnan&Gehrke, Chapter 3 CS4320 1

Lab 9 Access PreLab Copy the prelab folder, Lab09 PreLab9_Access_intro

The SQL Query Language. Creating Relations in SQL. Referential Integrity in SQL. Basic SQL Query. Primary and Candidate Keys in SQL

IT2304: Database Systems 1 (DBS 1)

Introduction to SQL and SQL in R. LISA Short Courses Xinran Hu

Security and Authorization. Introduction to DB Security. Access Controls. Chapter 21

Access Queries (Office 2003)

More on SQL. Juliana Freire. Some slides adapted from J. Ullman, L. Delcambre, R. Ramakrishnan, G. Lindstrom and Silberschatz, Korth and Sudarshan

When a variable is assigned as a Process Initialization variable its value is provided at the beginning of the process.

Unit 10: Microsoft Access Queries

Database Applications Microsoft Access

Microsoft Access 3: Understanding and Creating Queries

A Brief Introduction to MySQL

Oracle SQL. Course Summary. Duration. Objectives

Databases 2011 The Relational Model and SQL

Microsoft Excel 2007 Mini Skills Overview of Tables

Financial Data Access with SQL, Excel & VBA

SQL/PSM. Outline. Database Application Development Oracle PL/SQL. Why Stored Procedures? Stored Procedures PL/SQL. Embedded SQL Dynamic SQL

1 Structured Query Language: Again. 2 Joining Tables

Oracle Database: SQL and PL/SQL Fundamentals

2874CD1EssentialSQL.qxd 6/25/01 3:06 PM Page 1 Essential SQL Copyright 2001 SYBEX, Inc., Alameda, CA

Oracle Database: SQL and PL/SQL Fundamentals

SQL NULL s, Constraints, Triggers

Check out our website!

Database Query 1: SQL Basics

Database Administration with MySQL

History of SQL. Relational Database Languages. Tuple relational calculus ALPHA (Codd, 1970s) QUEL (based on ALPHA) Datalog (rule-based, like PROLOG)

Databases and BigData

Database Systems. Lecture 1: Introduction

Introduction to SQL for Data Scientists

Lecture 4: More SQL and Relational Algebra

Oracle Database 10g Express

SQL Basics. Introduction to Standard Query Language

HansaWorld SQL Training Material

Oracle Database 10g: Introduction to SQL

Oracle Database: SQL and PL/SQL Fundamentals NEW

Data Mining Commonly Used SQL Statements

SQL Server Database Coding Standards and Guidelines

Outline. Data Modeling. Conceptual Design. ER Model Basics: Entities. ER Model Basics: Relationships. Ternary Relationships. Yanlei Diao UMass Amherst

SQL. Short introduction

Jet Data Manager 2012 User Guide

MICROSOFT ACCESS A. CREATING A DATABASE B. CREATING TABLES IN A DATABASE

MS Access Lab 2. Topic: Tables

MS Excel. Handout: Level 2. elearning Department. Copyright 2016 CMS e-learning Department. All Rights Reserved. Page 1 of 11

The software shall provide the necessary tools to allow a user to create a Dashboard based on the queries created.

SQL Simple Queries. Chapter 3.1 V3.0. Napier University Dr Gordon Russell

Sample- for evaluation only. Introductory Access. TeachUcomp, Inc. A Presentation of TeachUcomp Incorporated. Copyright TeachUcomp, Inc.

SQL Tables, Keys, Views, Indexes

9.1 SAS. SQL Query Window. User s Guide

UNIT 6. Structured Query Language (SQL) Text: Chapter 5

Advance DBMS. Structured Query Language (SQL)

SQL Basics for RPG Developers

Inquiry Formulas. student guide

Retrieving Data Using the SQL SELECT Statement. Copyright 2006, Oracle. All rights reserved.

Microsoft Excel 2010 Part 3: Advanced Excel

SES Project v 9.0 SES/CAESAR QUERY TOOL. Running and Editing Queries. PS Query

Part A: Data Definition Language (DDL) Schema and Catalog CREAT TABLE. Referential Triggered Actions. CSC 742 Database Management Systems

CONVERTING FROM NETKEEPER ISAM v6.32 to NETKEEPER SQL

Exploring Microsoft Office Access Chapter 2: Relational Databases and Multi-Table Queries

Setting Up ALERE with Client/Server Data

Sales Person Commission

There are five fields or columns, with names and types as shown above.

CSC 443 Data Base Management Systems. Basic SQL

Microsoft Access Rollup Procedure for Microsoft Office Click on Blank Database and name it something appropriate.

A Comparison of Database Query Languages: SQL, SPARQL, CQL, DMX

ACCESS Importing and Exporting Data Files. Information Technology. MS Access 2007 Users Guide. IT Training & Development (818)

Ad Hoc Advanced Table of Contents

In this Lecture SQL SELECT. Example Tables. SQL SELECT Overview. WHERE Clauses. DISTINCT and ALL SQL SELECT. For more information

In This Lecture. SQL Data Definition SQL SQL. Notes. Non-Procedural Programming. Database Systems Lecture 5 Natasha Alechina

Transcription:

Query-by-Example (QBE) Module 3, Lecture 6 Example is the school of mankind, and they will learn at no other. -- Edmund Burke (1729-1797) Database Management Systems, R. Ramakrishnan 1

QBE: Intro A GUI for expressing queries. 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. Database Management Systems, R. Ramakrishnan 2

`Example Tables in QBE Users specify a query by filling in example tables, or skeletons; we will use these skeletons in our examples. Reserves sid bid day Boats bid bname color Database Management Systems, R. Ramakrishnan 3

Basics To print names and ages of all sailors: P._N P._A Print all fields for sailors with rating > 8, in ascending order by (rating, age): P. AO(1). >8 AO(2). QBE puts unique new variables in blank columns. Above query in DRC (no ordering): { I, N, T, A I, N, T, A Sailors T > 8} Database Management Systems, R. Ramakrishnan 4

And/Or Queries Names of sailors younger than 30 or older than 20: P. < 30 P. > 20 Names of sailors younger than 30 and older than 20: _Id P. < 30 _Id P. > 20 Names of sailors younger than 30 and rating > 4: _Id P. > 4 < 30 Note: MiniQBE uses a slightly different syntax! Database Management Systems, R. Ramakrishnan 5

Duplicates Single row with P: Duplicates not eliminated by default; can force elimination by using UNQ. UNQ. P. < 30 Multiple rows with P: Duplicates eliminated by default! Can avoid elimination by using ALL. ALL. _Id P. < 30 _Id P. > 20 Database Management Systems, R. Ramakrishnan 6

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): _Id P._S > 25 Reserves sid bid day _Id 8/24/96 Joins accomplished by repeating variables. Note: MiniQBE uses double quotes Database Management Systems, R. Ramakrishnan 7

Join Queries (Contd.) Colors of boats reserved by sailors who ve reserved a boat for 8/24/96 and are older than 25 : _Id _S > 25 Reserves sid bid day _Id _B 8/24/96 Boats bid bname color _B Interlake P. Database Management Systems, R. Ramakrishnan 8

Join Queries (Contd.) Names and ages of sailors who ve reserved some boat that is also reserved by the sailor with sid = 22: _Id P. P. Reserves sid bid day 22 _B _Id _B Database Management Systems, R. Ramakrishnan 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! _Id P. _R _A P._D P.(_R/_A) Reserves sid bid day _Id _D Database Management Systems, R. Ramakrishnan 10

Negative Tables Can place a negation marker in the relation column: _Id P._S Reserves sid bid day _Id _B Note: Variables appearing in a negated table must also appear in a positive table! MiniQBE uses NOT or ~. Database Management Systems, R. Ramakrishnan 11

Aggregates QBE supports AVG, COUNT, MIN, MAX, SUM None of these eliminate duplicates, except COUNT Also have AVG.UNQ. etc. to force duplicate elimination _Id G. G.P.AO _A P.AVG._A 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. Database Management Systems, R. Ramakrishnan 12

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: G.P. _A CONDITIONS AVG._A > 30 Express conditions involving AND and OR: P. _A CONDITIONS 20 < _A AND _A < 30 Database Management Systems, R. Ramakrishnan 13

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. P.G._Id Reserves sid bid day _Id _B1 Boats bid bname color _B2 CONDITIONS COUNT._B1= COUNT._B2 How can we modify this query to print the names of sailors who ve reserved all boats? Database Management Systems, R. Ramakrishnan 14

Inserting Tuples Single-tuple insertion: I. 74 Janice 7 14 Inserting multiple tuples (rating is null in tuples inserted below): I. _Id _N _A Students sid name login age _Id _N _A CONDITIONS _A > 18 OR _N LIKE C% Database Management Systems, R. Ramakrishnan 15

Delete and Update Delete all reservations for sailors with rating < 4 _Id < 4 Reserves sid bid day D. _Id Increment the age of the sailor with sid = 74 74 U._A+1 Database Management Systems, R. Ramakrishnan 16

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: john _A joe U._A+1 Should we update every Joe s age? Which John s age should we use? Database Management Systems, R. Ramakrishnan 17

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: _Id P._S Boats bid bname color Reserves sid bid day _B _Id _B Illegal query! Variable _B does not appear in a positive row. In what order should the two negative rows be considered? (Meaning changes!) Database Management Systems, R. Ramakrishnan 18

A Solution Using Views Find sailors who ve not reserved some boat _B: _Id P._S BadSids sid I. _Id Boats bid bname color Reserves sid bid day _B _Id _B Next, find sailors not in this `bad set: _Id P._S BadSids sid _Id Database Management Systems, R. Ramakrishnan 19

A Peek at MS Access Database Management Systems, R. Ramakrishnan 20

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. Database Management Systems, R. Ramakrishnan 21