SlideShare a Scribd company logo
1 of 29
CS 222
 Database Management System
                    Spring 2010-11


                  Lecture 3


              Korra Sathya Babu
           Department of Computer Science
                   NIT Rourkela
02/11/13                Lecture 3           1
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




    02/11/13                     Lecture 3                        2
Query-by-Example (QBE)
Query-by-Example (QBE)
• 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”
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.
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
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)
Example
Sno    Sname        Ratin   Age    Sid   bid          day   bid       bname           color
                     g             22    101     10/10/08   101      Interlake        Blue
22     Dustine       7      45.0
                                   22    102     10/10/08   102      Interlake        Red
29      Brutus       1      33.0
                                   22    103     10/08/08   103       Clipper     Green
31     Lubber        8      55.5
                                   22    104     10/07/08   104       Marine          red
32      Andy         8      25.5
                                   31    102     10/10/08         Instance of Boats
58      Rusty        10     35.0
                                   31    103     11/06/08
64     Horatio       7      35.0
                                   31    104     11/12/08
71      Zorba        10     16.0
                                   64    101     09/05/08
74     Horatio       9      35.0
85        Art        3      25.5   64    102     09/08/08

95       Bob         3      63.5   74    103     09/08/08

      Instance of                  Instance of Reserves
      Sailors



       02/11/13                           Lecture 3                               8
`Example Tables’ in QBE
                                   Relation name   attributes



• QBE has its own screen          Reserves sid bid              day
  editor
• Users specify a query by
  filling in example tables, or
  skeletons; we will use          Boats bid bname color
  these skeletons in our
  examples.


                          Sailors sid sname rating age
`Creating Tables’ in QBE

Dictionary entry for Relation Reserves




             I.P.I. Reserves                                     sid              bid                  day



                                         Represent the dictionary entry of file columns of table Reserves
Basics
• To print names and ages of all sailors:
   Sailors sid sname rating age
               P._N         P._A
 Print all fields for sailors with rating > 8, in
 ascending order by (rating, age):
 Sailors sid sname 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}
And/Or Queries
• Names of sailors younger than 30 or older
  than 20: Sailors sid sname rating age
                       P.            < 30
                       P.            > 20
 Names of sailors younger than 30 and older than
 20: Sailors sid sname rating age
              _Id P.             < 30
              _Id P.             > 20
  Names of sailors younger than 30 and rating > 4:
     Sailors sid sname rating age
             _Id P.         > 4 < 30
Duplicates
• Single row with P: Duplicates not eliminated
  by default; can force elimination by using
  UNQ.
       Sailors sid sname rating age
       UNQ.        P.           < 30

  Multiple rows with P: Duplicates eliminated by
  default! Can avoid elimination by using ALL.
       Sailors sid sname rating age
       ALL. _Id P.              < 30
               _Id P.           > 20
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):
                Sailors   sid sname      rating   age
                          _Id P._S                > 25
                  Reserves   sid   bid    day
                             _Id         ‘8/24/96’

 Joins accomplished by repeating variables.
Join Queries (Contd.)
• Colors of boats reserved by sailors who’ve
  reserved a boat for 8/24/96 and are older
  than 25 :
       Sailors sid sname rating age
               _Id _S           > 25
        Reserves sid bid day
                 _Id _B ‘8/24/96’
         Boats bid bname     color
               _B ‘Interlake’ P.
Join Queries (Contd.)
• Names and ages of sailors who’ve reserved
  some boat that is also reserved by the sailor
  with sid = 22:
        Sailors sid sname rating age
                _Id P.           P.

          Reserves sid bid   day
                   22 _B
                   _Id _B
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!
 Sailors sid sname rating age
         _Id P.      _R _A P._D P.(_R/_A)

          Reserves sid bid day
                   _Id     _D
“Negative Tables”
• Can place a negation marker in the
  relation column:
     Sailors sid sname rating age
             _Id P._S
      Reserves sid bid    day
         ¬     _Id _B

  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
 Sailors sid sname rating   age
          _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 to get the aggregates.
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:

  Sailors sid sname rating age      CONDITIONS
                      G.P. _A       AVG._A > 30
   Express conditions involving AND and OR:
Sailors sid sname rating age    CONDITIONS
            P.           _A     20 < _A AND _A < 30
Find sailors who’ve reserved all boats
• A division query; need aggregates (or update
  operations) to do this in QBE.

      Sailors sid     sname rating age
              P.G._Id

Reserves sid bid day        CONDITIONS
         _Id _B1            COUNT._B1= COUNT._B2


           Boats bid bname      color
                 _B2
Inserting Tuples
• Tuple insertion:


      Sailors sid sname rating age
      I.      74 Janice   7    14
Delete and Update
• Delete all reservations for sailors with rating < 4
         Sailors sid sname rating age
                 _Id         <4

              Reserves sid bid        day
              D.       _Id

  Increment the age of the sailor with sid = 74
         Sailors sid sname rating age
                 74               U._A+1
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:
       Sailors sid sname rating age
                   john         _A
                   joe          U._A+1
      Should we update every Joe’s age?
      Which John’s age should we use?
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:
           Sailors sid sname rating age
                   _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!)
A Solution Using Views
• Find sailors who’ve not reserved some boat _B:


  Sailors sid sname rating age                 BadSids sid
          _Id P._S                             I.      _Id

Boats bid bname color
                               ¬
                            Reserves sid bid         day
      _B                             _Id _B

   Next, find sailors not in this `bad’ set:

                                                 ¬
  Sailors sid sname rating age                 BadSids sid
          _Id P._S                                     _Id
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
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
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.

More Related Content

What's hot

2.software requirement specification
2.software requirement specification2.software requirement specification
2.software requirement specificationDeepak Sharma
 
Enterprise Information Systems
Enterprise Information SystemsEnterprise Information Systems
Enterprise Information SystemsGoutama Bachtiar
 
Transaction processing system (TPS)
Transaction processing system (TPS)Transaction processing system (TPS)
Transaction processing system (TPS)Jaisha Jaikishan
 
Database Design
Database DesignDatabase Design
Database Designlearnt
 
System Design Presentation
System Design PresentationSystem Design Presentation
System Design PresentationSCOUT9989
 
FORMAL & INFORMAL INFORMATION SYSTEM
FORMAL & INFORMAL  INFORMATION SYSTEMFORMAL & INFORMAL  INFORMATION SYSTEM
FORMAL & INFORMAL INFORMATION SYSTEMZahid Parvez
 
ppt on sOFTWARE DEVELOPMENT LIFE CYCLE
 ppt on sOFTWARE DEVELOPMENT LIFE CYCLE ppt on sOFTWARE DEVELOPMENT LIFE CYCLE
ppt on sOFTWARE DEVELOPMENT LIFE CYCLESwarnima Tiwari
 
Rapid Application Development Model
Rapid Application Development ModelRapid Application Development Model
Rapid Application Development ModelDamian T. Gordon
 
Decision table
Decision tableDecision table
Decision tableDMANIMALA
 
Object oriented and function oriented design
Object oriented and function oriented designObject oriented and function oriented design
Object oriented and function oriented designNaveen Sagayaselvaraj
 
Planning, design and implementation of information systems
Planning, design and implementation of information systemsPlanning, design and implementation of information systems
Planning, design and implementation of information systemsOnline
 
1. introduction to uml
1. introduction to uml1. introduction to uml
1. introduction to umlPRABU M
 
Ch6 formal relational query languages
Ch6 formal relational query languages Ch6 formal relational query languages
Ch6 formal relational query languages uoitc
 
source code metrics and other maintenance tools and techniques
source code metrics and other maintenance tools and techniquessource code metrics and other maintenance tools and techniques
source code metrics and other maintenance tools and techniquesSiva Priya
 
Database system environment ppt.
Database system environment ppt.Database system environment ppt.
Database system environment ppt.yhen06
 
System Analysis and Design
System Analysis and DesignSystem Analysis and Design
System Analysis and DesignAamir Abbas
 

What's hot (20)

2.software requirement specification
2.software requirement specification2.software requirement specification
2.software requirement specification
 
Enterprise Information Systems
Enterprise Information SystemsEnterprise Information Systems
Enterprise Information Systems
 
Transaction processing system (TPS)
Transaction processing system (TPS)Transaction processing system (TPS)
Transaction processing system (TPS)
 
Dbms4
Dbms4Dbms4
Dbms4
 
Database Design
Database DesignDatabase Design
Database Design
 
System Design Presentation
System Design PresentationSystem Design Presentation
System Design Presentation
 
FORMAL & INFORMAL INFORMATION SYSTEM
FORMAL & INFORMAL  INFORMATION SYSTEMFORMAL & INFORMAL  INFORMATION SYSTEM
FORMAL & INFORMAL INFORMATION SYSTEM
 
ppt on sOFTWARE DEVELOPMENT LIFE CYCLE
 ppt on sOFTWARE DEVELOPMENT LIFE CYCLE ppt on sOFTWARE DEVELOPMENT LIFE CYCLE
ppt on sOFTWARE DEVELOPMENT LIFE CYCLE
 
Mis
MisMis
Mis
 
Decision support system
Decision support systemDecision support system
Decision support system
 
Rapid Application Development Model
Rapid Application Development ModelRapid Application Development Model
Rapid Application Development Model
 
Decision table
Decision tableDecision table
Decision table
 
Object oriented and function oriented design
Object oriented and function oriented designObject oriented and function oriented design
Object oriented and function oriented design
 
Planning, design and implementation of information systems
Planning, design and implementation of information systemsPlanning, design and implementation of information systems
Planning, design and implementation of information systems
 
1. introduction to uml
1. introduction to uml1. introduction to uml
1. introduction to uml
 
Ch6 formal relational query languages
Ch6 formal relational query languages Ch6 formal relational query languages
Ch6 formal relational query languages
 
source code metrics and other maintenance tools and techniques
source code metrics and other maintenance tools and techniquessource code metrics and other maintenance tools and techniques
source code metrics and other maintenance tools and techniques
 
Database system environment ppt.
Database system environment ppt.Database system environment ppt.
Database system environment ppt.
 
Lecture2
Lecture2Lecture2
Lecture2
 
System Analysis and Design
System Analysis and DesignSystem Analysis and Design
System Analysis and Design
 

Viewers also liked

General form of a research paper presentation
General form of a research paper presentationGeneral form of a research paper presentation
General form of a research paper presentationWaqar Younus
 
Column Level Encryption in Microsoft SQL Server
Column Level Encryption in Microsoft SQL ServerColumn Level Encryption in Microsoft SQL Server
Column Level Encryption in Microsoft SQL ServerBehnam Mohammadi
 
CH02-Fundamental of WWW and Internet
CH02-Fundamental of WWW and InternetCH02-Fundamental of WWW and Internet
CH02-Fundamental of WWW and InternetSukanya Ben
 
Chapter 10 database management
Chapter 10   database managementChapter 10   database management
Chapter 10 database managementhaider ali
 
Chapter 6 output
Chapter 6   outputChapter 6   output
Chapter 6 outputhaider ali
 
Chapter 12 information system development
Chapter 12   information system developmentChapter 12   information system development
Chapter 12 information system developmenthaider ali
 
Database Systems - Introduction (Chapter 1)
Database Systems - Introduction (Chapter 1)Database Systems - Introduction (Chapter 1)
Database Systems - Introduction (Chapter 1)Vidyasagar Mundroy
 
Operating Systems and Utility Programs
Operating Systems and Utility ProgramsOperating Systems and Utility Programs
Operating Systems and Utility ProgramsSamudin Kassan
 
Meanings of Colours
Meanings of ColoursMeanings of Colours
Meanings of Colourscircewine
 
Health And Safety Induction Training
Health And Safety Induction TrainingHealth And Safety Induction Training
Health And Safety Induction Trainingedale07
 

Viewers also liked (14)

Dialog design
Dialog designDialog design
Dialog design
 
General form of a research paper presentation
General form of a research paper presentationGeneral form of a research paper presentation
General form of a research paper presentation
 
Column Level Encryption in Microsoft SQL Server
Column Level Encryption in Microsoft SQL ServerColumn Level Encryption in Microsoft SQL Server
Column Level Encryption in Microsoft SQL Server
 
YOUNG INDIA (3) (1)
YOUNG  INDIA (3) (1)YOUNG  INDIA (3) (1)
YOUNG INDIA (3) (1)
 
CH02-Fundamental of WWW and Internet
CH02-Fundamental of WWW and InternetCH02-Fundamental of WWW and Internet
CH02-Fundamental of WWW and Internet
 
Chapter 10 database management
Chapter 10   database managementChapter 10   database management
Chapter 10 database management
 
Mysql database
Mysql databaseMysql database
Mysql database
 
Chapter 6 output
Chapter 6   outputChapter 6   output
Chapter 6 output
 
Chapter 12 information system development
Chapter 12   information system developmentChapter 12   information system development
Chapter 12 information system development
 
Database Systems - Introduction (Chapter 1)
Database Systems - Introduction (Chapter 1)Database Systems - Introduction (Chapter 1)
Database Systems - Introduction (Chapter 1)
 
Operating Systems and Utility Programs
Operating Systems and Utility ProgramsOperating Systems and Utility Programs
Operating Systems and Utility Programs
 
Meanings of Colours
Meanings of ColoursMeanings of Colours
Meanings of Colours
 
Health And Safety Induction Training
Health And Safety Induction TrainingHealth And Safety Induction Training
Health And Safety Induction Training
 
Usability Testing Report Template
Usability Testing Report TemplateUsability Testing Report Template
Usability Testing Report Template
 

Dbms1

  • 1. CS 222 Database Management System Spring 2010-11 Lecture 3 Korra Sathya Babu Department of Computer Science NIT Rourkela 02/11/13 Lecture 3 1
  • 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 02/11/13 Lecture 3 2
  • 4. Query-by-Example (QBE) • 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 Sno Sname Ratin Age Sid bid day bid bname color g 22 101 10/10/08 101 Interlake Blue 22 Dustine 7 45.0 22 102 10/10/08 102 Interlake Red 29 Brutus 1 33.0 22 103 10/08/08 103 Clipper Green 31 Lubber 8 55.5 22 104 10/07/08 104 Marine red 32 Andy 8 25.5 31 102 10/10/08 Instance of Boats 58 Rusty 10 35.0 31 103 11/06/08 64 Horatio 7 35.0 31 104 11/12/08 71 Zorba 10 16.0 64 101 09/05/08 74 Horatio 9 35.0 85 Art 3 25.5 64 102 09/08/08 95 Bob 3 63.5 74 103 09/08/08 Instance of Instance of Reserves Sailors 02/11/13 Lecture 3 8
  • 9. `Example Tables’ in QBE Relation name attributes • QBE has its own screen Reserves sid bid day editor • Users specify a query by filling in example tables, or skeletons; we will use Boats bid bname color these skeletons in our examples. Sailors sid sname rating age
  • 10. `Creating Tables’ in QBE Dictionary entry for Relation Reserves I.P.I. Reserves sid bid day Represent the dictionary entry of file columns of table Reserves
  • 11. Basics • To print names and ages of all sailors: Sailors sid sname rating age P._N P._A Print all fields for sailors with rating > 8, in ascending order by (rating, age): Sailors sid sname 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}
  • 12. And/Or Queries • Names of sailors younger than 30 or older than 20: Sailors sid sname rating age P. < 30 P. > 20 Names of sailors younger than 30 and older than 20: Sailors sid sname rating age _Id P. < 30 _Id P. > 20 Names of sailors younger than 30 and rating > 4: Sailors sid sname rating age _Id P. > 4 < 30
  • 13. Duplicates • Single row with P: Duplicates not eliminated by default; can force elimination by using UNQ. Sailors sid sname rating age UNQ. P. < 30 Multiple rows with P: Duplicates eliminated by default! Can avoid elimination by using ALL. Sailors sid sname rating age ALL. _Id P. < 30 _Id P. > 20
  • 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): Sailors sid sname rating age _Id P._S > 25 Reserves sid bid day _Id ‘8/24/96’ 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 : Sailors sid sname rating age _Id _S > 25 Reserves sid bid day _Id _B ‘8/24/96’ Boats bid bname color _B ‘Interlake’ P.
  • 16. Join Queries (Contd.) • Names and ages of sailors who’ve reserved some boat that is also reserved by the sailor with sid = 22: Sailors sid sname rating age _Id P. P. Reserves sid bid day 22 _B _Id _B
  • 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! Sailors sid sname rating age _Id P. _R _A P._D P.(_R/_A) Reserves sid bid day _Id _D
  • 18. “Negative Tables” • Can place a negation marker in the relation column: Sailors sid sname rating age _Id P._S Reserves sid bid day ¬ _Id _B 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 Sailors sid sname rating age _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 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: Sailors sid sname rating age CONDITIONS G.P. _A AVG._A > 30 Express conditions involving AND and OR: Sailors sid sname rating age CONDITIONS P. _A 20 < _A AND _A < 30
  • 21. Find sailors who’ve reserved all boats • A division query; need aggregates (or update operations) to do this in QBE. Sailors sid sname rating age P.G._Id Reserves sid bid day CONDITIONS _Id _B1 COUNT._B1= COUNT._B2 Boats bid bname color _B2
  • 22. Inserting Tuples • Tuple insertion: Sailors sid sname rating age I. 74 Janice 7 14
  • 23. Delete and Update • Delete all reservations for sailors with rating < 4 Sailors sid sname rating age _Id <4 Reserves sid bid day D. _Id Increment the age of the sailor with sid = 74 Sailors sid sname rating age 74 U._A+1
  • 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: Sailors sid sname rating age john _A joe U._A+1 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: Sailors sid sname rating age _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!)
  • 26. A Solution Using Views • Find sailors who’ve not reserved some boat _B: Sailors sid sname rating age BadSids sid _Id P._S I. _Id Boats bid bname color ¬ Reserves sid bid day _B _Id _B Next, find sailors not in this `bad’ set: ¬ Sailors sid sname rating age BadSids sid _Id P._S _Id
  • 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.

Editor's Notes

  1. 1
  2. 3
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. Print the sname field of Sailors tuples such that there is no tuple in Reserves with the same value in the sid field.”
  12. 13
  13. 14
  14. 15 How can we modify this query to print the names of sailors who’ve reserved all boats?
  15. 16 How to insert multiple tuples
  16. 17
  17. 18 This update seeks to change Joe’s age based on John’s age. Since sname is not a key, the meaning of such a query is ambiguous—should we update every John’s age, and if so, based on which Joe’s age?
  18. 19 This query is illegal because the variable B does not appear in any positive row. Going beyond this technical objection, this QBE query is ambiguous with respect to the ordering of the two uses of ¬ . It could denote either the calculus query that we want to express or the following calculus query, which is not what we want: {I,N, T,A | I,N, T,A ∈ Sailors∧ ¬∃ Ir,Br,D ∈ Reserves ( ¬∃ B, BN,C ∈ Boats(I = Ir ∧ Br = B))} There is no mechanism in QBE to control the order in which the ¬ operations in a query are applied. (Incidentally, the above query finds all Sailors who have made reservations only for boats that exist in the Boats relation.)
  19. 20
  20. 22
  21. 22
  22. 22 It is quite expressive (relationally complete, if the update features are taken into account).