Presentation is loading. Please wait.

Presentation is loading. Please wait.

5/15/2015Lecture 31 CS 222 Database Management System Spring 2010-11 Lecture 3 Korra Sathya Babu Department of Computer Science NIT Rourkela.

Similar presentations


Presentation on theme: "5/15/2015Lecture 31 CS 222 Database Management System Spring 2010-11 Lecture 3 Korra Sathya Babu Department of Computer Science NIT Rourkela."— Presentation transcript:

1 5/15/2015Lecture 31 CS 222 Database Management System Spring 2010-11 Lecture 3 Korra Sathya Babu Department of Computer Science NIT Rourkela

2 Commercial Query Languages RA and RC are formal and abstract Languages developed for the Relational model in the database technology Many languages were commercialized taking the foundations from the abstract query languages –QBE –QUEL –SQL 5/15/2015Lecture 32

3 Query-by-Example (QBE)

4 Developed by Moshe M. Zoolf at IBM Research during mid 1970s (in parallel to the development of SQL) A graphical query language which is based on the notion of DRC –QBE queries can be translated to DRC directly but queries containing aggregate operators, sorting etc cannot be converted Two dimensional syntax – system creates templates of relations that are requested by users Queries are expressed “by example”

5 Query-by-Example (QBE) A “GUI” for expressing queries. –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.

6 Syntax QBE Queries are posed by placing constants and variables (example elements) into individual columns and thereby creating an example tuple of the query result Variables used are domain variables Variable symbols are prefixed by underscore Commands are followed by a dot The field that should appear in the answer are specified by the command P. (stands for Print ( also called retrieval command )) Equal operator is by default. Other comparison operators can also be used Link establishment between relations is done by example elements

7 Syntax Aggregate functions and Groupings used by adding prefixes are –CNT.ALL. –SUM.ALL. –CNT.UNQ.ALL. –MAX.ALL. –MIN.ALL –AVG.ALL –MOD.ALL –G. (Groupings) Sorting commands used are –.DO (Descending Order) –.AO ( Ascending Order) General Commands used are –P. (Print), I. (Insert), U. (Update), D. (Delete)

8 Example 5/15/2015Lecture 38 SnoSnameRatingAge 22Dustine745.0 29Brutus133.0 31Lubber855.5 32Andy825.5 58Rusty1035.0 64Horatio735.0 71Zorba1016.0 74Horatio935.0 85Art325.5 95Bob363.5 Sidbidday 2210110/10/08 2210210/10/08 2210310/08/08 2210410/07/08 3110210/10/08 3110311/06/08 3110411/12/08 6410109/05/08 6410209/08/08 7410309/08/08 bidbnamecolor 101InterlakeBlue 102InterlakeRed 103ClipperGreen 104Marinered Instance of Sailors Instance of Reserves Instance of Boats

9 `Example Tables’ in QBE QBE has its own screen editor Users specify a query by filling in example tables, or skeletons; we will use these skeletons in our examples. Relation name attributes

10 `Creating Tables’ in QBE Dictionary entry for Relation Reserves Represent the dictionary entry of file columns of table Reserves I.P.I.

11 Basics 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):

12 And/Or Queries 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:

13 Duplicates 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.

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

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

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

17 Unnamed Columns 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!

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

19 Aggregates 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 to get the aggregates.

20 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: v Express conditions involving AND and OR:

21 Find sailors who’ve reserved all boats A division query; need aggregates (or update operations) to do this in QBE.

22 Inserting Tuples Tuple insertion:

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

24 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?

25 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: v Illegal query! Variable _B does not appear in a positive row. In what order should the two negative rows be considered? (Meaning changes!)

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

27 Advantages of QBE User-friendly Order of the row is immaterial Highly non procedural query language Several ways to represent a query QBE is interpreter based so debugging is easy

28 Disadvantages of QBE QBE doesn’t support complete views QBE doesn’t have a preprocessor for optimization Implementation of QBE is not complete but theoretically its complete

29 Summary QBE is an elegant, user-friendly query language based on DRC. 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.


Download ppt "5/15/2015Lecture 31 CS 222 Database Management System Spring 2010-11 Lecture 3 Korra Sathya Babu Department of Computer Science NIT Rourkela."

Similar presentations


Ads by Google