Chapter 5 Other Relational Languages By Cui, Can B.

Slides:



Advertisements
Similar presentations
Chapter 5: Other Relational Languages
Advertisements

Database System Concepts, 5th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 5: Other Relational.
Relational Calculus and Datalog
Chapter 5: Other Relational Languages
Relational Algebra, Join and QBE Yong Choi School of Business CSUB, Bakersfield.
©Silberschatz, Korth and Sudarshan5.1Database System Concepts Chapter 5: Other Relational Languages Query-by-Example (QBE) Datalog.
Ver 1,12/09/2012Kode :CCs 111,Sistem basis DataFASILKOM Chapter 3: SQL Bambang Irawan Database System Concepts, 5th Ed. ©Silberschatz, Korth and Sudarshan.
Ver 1,12/09/2012Kode :CCs 111,Sistem basis DataFASILKOM Chapter 5: Other Relational Languages Database System Concepts, 5th Ed. ©Silberschatz, Korth and.
Ver 1,12/09/2012Kode :CCs 111,sistem basisdataFASILKOM Chapter 2: Relational Model Database System Concepts, 5th Ed. ©Silberschatz, Korth and Sudarshan.
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.
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.
Domain Relational Calculus and Query-by-Example CS157a John Eagle.
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.
©Silberschatz, Korth and Sudarshan4.1Database System Concepts Ordering the Display of Tuples List in alphabetic order the names of all customers having.
©Silberschatz, Korth and Sudarshan4.1Database System Concepts Chapter 4: SQL Basic Structure Set Operations Aggregate Functions Null Values Nested Subqueries.
Temple University – CIS Dept. CIS331– Principles of Database Systems V. Megalooikonomou Query by example (based on notes by Silberchatz,Korth, and Sudarshan.
Slides adapted from A. Silberschatz et al. Database System Concepts, 5th Ed. SQL - part 2 - Database Management Systems I Alex Coman, Winter 2006.
Relational Algebra. Relational Query Languages n Query = “retrieval program” n Language examples: ù Theoretical : 1. Relational Algebra 2. Relational.
Query-by-Example (QBE) Presented by: Wong, Lok Man CS 157A Dr. Sin Min Lee.
Database System Concepts, 5th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 5: Other Relational.
©Silberschatz, Korth and Sudarshan4.1Database System Concepts Chapter 4: SQL Basic Structure Set Operations Aggregate Functions Null Values Nested Subqueries.
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.
Lecture 6 Structured Query Language SQL Lecture 6 Structured Query Language SQL Instructor: Haya Sammaneh.
3.1 Chapter 3: SQL Schema used in examples p (omit 3.8.2, , 3.11)
Chapter 5: Other Relational Languages. 5.2 Chapter 5: Other Relational Languages Tuple Relational Calculus Domain Relational Calculus Query-by-Example.
Relational Algebra Instructor: Mohamed Eltabakh 1.
CS 370 Database Systems Lecture 12 Introduction to SQL.
©Silberschatz, Korth and Sudarshan2.1Database System Concepts - 5 th Edition, Oct 5, 2006 Outer Join n An extension of the join operation that avoids loss.
SQL: Data Manipulation Presented by Mary Choi For CS157B Dr. Sin Min Lee.
©Silberschatz, Korth and Sudarshan5.1Database System Concepts Chapter 5: Other Relational Languages Query-by-Example (QBE)
Computing & Information Sciences Kansas State University Thursday, 08 Feb 2007CIS 560: Database System Concepts Lecture 11 of 42 Thursday, 08 February.
©Silberschatz, Korth and Sudarshan5.1Database System Concepts Chapter 5: Other Relational Query Languages Tuple Relational Calculus Domain Relational Calculus.
BACS 287 Structured Query Language 1. BACS 287 Visual Basic Table Access Visual Basic provides 2 mechanisms to access data in tables: – Record-at-a-time.
Chapter 8: SQL. Data Definition Modification of the Database Basic Query Structure Aggregate Functions.
©Silberschatz, Korth and Sudarshan5.1Database System Concepts Chapter 5: Other Relational Languages Query-by-Example (QBE) Quel Datalog.
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.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Appendix C: Other Relational.
Database System Concepts, 5th Ed. Bin Mu at Tongji University Chapter 5: Other Relational Languages.
©Silberschatz, Korth and Sudarshan3.1Database System Concepts Extended Relational-Algebra-Operations Generalized Projection Aggregate Functions Outer Join.
Computing & Information Sciences Kansas State University Friday, 08 Sep 2006CIS 560: Database System Concepts Lecture 07 of 42 Tuesday, 30 January 2007.
Computing & Information Sciences Kansas State University Wednesday, 17 Sep 2008CIS 560: Database System Concepts Lecture 9 of 42 Wednesday, 18 September.
©Silberschatz, Korth and Sudarshan5.1Database System Concepts Chapter 5: Other Relational Languages Query-by-Example (QBE) Datalog.
Database System Concepts, 5th Ed. ©Silberschatz, Korth and Sudarshan Chapter 5: Other Relational Languages.
Lu Chaojun, SJTU 1 Extended Relational Algebra. Bag Semantics A relation (in SQL, at least) is really a bag (or multiset). –It may contain the same tuple.
SCUHolliday - coen 1787–1 Schedule Today: u Subqueries, Grouping and Aggregation. u Read Sections Next u Modifications, Schemas, Views. u Read.
Database System Concepts, 5th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 5: Other Relational.
Structured Query Language
CS 480: Database Systems Lecture 17 February 22, 2013.
Prof: Dr. Shu-Ching Chen TA: Hsin-Yu Ha
Structured Query Language (Data Manipulation Language)
Relational Model By Dr.S.Sridhar, Ph.D.(JNUD), RACI(Paris, NICE), RMR(USA), RZFM(Germany)
Query-by-Example (QBE)
Schedule Today: Next After that Subqueries, Grouping and Aggregation.
Lecture on Relational Languages
SQL Structured Query Language 11/9/2018 Introduction to Databases.
Prof: Dr. Shu-Ching Chen TA: Yimin Yang
Prof: Dr. Shu-Ching Chen TA: Hsin-Yu Ha
Chapter 5: Other Relational Languages
SQL LANGUAGE and Relational Data Model TUTORIAL
Instructor: Mohamed Eltabakh
Prof: Dr. Shu-Ching Chen TA: Haiman Tian
Schedule Today: Next And then Relational Algebra.
Appendix C: Other Relational Languages
Shelly Cashman: Microsoft Access 2016
CS 405G: Introduction to Database Systems
Presentation transcript:

Chapter 5 Other Relational Languages By Cui, Can B.

The Languages Query By Example (QBE) – Base on domain relational calculus. Quel – Base on tuple relational calculus. Datalog – modeled after the Prolog Language.

I. QBE: Introduction For Data Manipulation 1. It has two dimensional syntax, so it requires two dimensions for its expressions. 2. QBE queries are expressed “by example.”

QBE tables Users specify a query by filling in tables. Reserves sid bid day Books bid btitle type Student sid sname class age

Basics Print names and ages of all students: Sid Sname Class age P._N P._A Print all fields of students who are at least sophomores in ascending order by (class, age): Student Sid Sname Class age P. AO(1). > sophomore AO(2).

Continue Print unique student names older than 25. Names of student younger than 20 or older than 25: Student Sid Sname Class age P. >25 <20 Duplicates not eliminated by default: Student Sid Sname Class age UNQ P. <25 Print unique student names older than 25.

Join Queries Print students who borrowed a book on 11/30/01. Joins are accomplished by repeating variables Student Sid Sname Class Age _Id P.S Reserves Sid Bid day _Id `11/30/01’ sid is the common attribute that join the two tables. Print students who borrowed a book on 11/30/01.

Join Queries Types of books reserved by students who have reserved a book for 11/30/01 and are older than 25. Student Sid Sname Class age _Id _S >25 Reserves Sid Bid day _Id _B `11/30/01’ Books Bid Bname type _B P.

Aggregates QBE supports: AVG, COUNT, MIN, MAX, SUM Student Sid Sname Class age _Id G. G.P.AO _A P.AVG._A G. are the group by fields – All tuples have the same values. Unnamed columns – Print result of an expression.

Conditions Box Used to express conditions involving 2 or more columns. Conditions can be expressed involving a group. Student Sid Sname Class age P. _A CONDITIONS 20 < _A AND _A <25 Print student names that are between the ages of 20 and 25.

Inserting & Deleting Tuples Tuple insertion: Student Sid Sname Class age I. 1369 Lisa Senior 23 Tuple deletion: Delete all reservations for students with age<23 Student Sid Sname Class age _Id < 23 Reserves Sid Bid day D. _Id

II. Quel – Basic Structure Range of t is r - Declares t to be a tuple variable restricted to take on values of tuples in relation r. Retrieve (t.attribute) - The retrieve clause is similar in function to the select clause of SQL.

Continue… Where P - The where clause contains the selection predicate.

Quel Query Structure Range of t is r Retrieve (t.A) Where P Each t is a tuple variable. Each r is a relation. Each A is an attribute. The notation t.A denotes the value of tuple variable t on attribute A.

Example Range of t is borrower Retrieve (t.CustomerName) Find the names of all customers having a loan at the bank. Range of t is borrower Retrieve (t.CustomerName)

Example: Tuple Variables Certain queries need 2 variables over the same relation. Example: Find all customers who live in the same city as Smith. Range of s is customer Range of t is customer Retrieve ( s.CustName ) Where t.CustName = “Smith and s.CustCity = t.CustCity

Aggregate Function Aggregate functions in Quel compute functions on groups of tuples. An aggregate expression appear anywhere a constant may appear.

For Example In a where clause. Find the average balance for all San Jose accounts. Range of t is account Retrieve avg (t.balance Where t.Branch = “San Jose”)

Modification of Database Deletion: The form of a Quel deletion is: range of t is r delete t where p t can be implicitly defined. Predicate P can be any valid Quel predicate. If the where clause is omitted, all tuples in the relation are deleted.

Example: Delete all of Lee’s account record: range of t is depositor delete t where t.CustName = “Lee”

Insertion append to account (branch = “San Jose” account = “123456” Insertions are expressed in Quel using the append to. Insert the account 123456 at the San Jose branch with a balance of $5000.00: append to account (branch = “San Jose” account = “123456” balance = “5000”)

Updates Updates are expressed in Quel using the replace command Increase all account balances by 5 percent: range of t is account replace t (balance = 1.05 * t.balance)

III. Datalog – Basic Structure Logic based language that allows recursive queries. A Datalog program consists of a set of rules that defines views.

Example: Define a view relation vt containing account numbers and balances for accounts at the San Jose branch with a balance of over $100. vt (A B) :- account ( “San Jose”, A B) B > 100 for all A,B if (“San Jose”, A,B) E account A and B > 100 then (A,B) E vt

Datalog Rules A positive literal has the form: p(t1,t2,…,tn) A negative literal has the form: not p(t1,t2,…,tn) p is the name of the relation with n attributes. Each t is a constant or variable.

Continue… Rules are built out of literals and have the form: p(t1,t2,…,tn) :- L1,L2…Ln Each L is a literal Head – the literal p(t1,t2,…,tn) Body – the rest of the literals.

Semantics of a Rule An instantiation rule is the result of replacing each variable in the rule by some constant. Rule defining v1: v1 (A,B):- account(“SanJose”, A,B), B>100 An instantiation Rule: v1 (123456, 300) :- account (“San Jose”, “123456”,300) 300 > 100

Semantics of Recursion in Datalog The view relations of a recursive program containing a set of rules K are defied to contain exactly the set of facts /.  facts / are derived from rules K. Facts / is compute by a recursive procedure called Datalog-Fixpoint: Procedure Datalog- Fixpoint / = set of facts in the database repeat Old./ = / / = / U infer (K,/) until / = Old./ At the end of the procedure, infer ( K, / )= / Datalog-Fixpoint will computes all the facts / until the rules in the program has all negative literal or no more true record according to the rules K.

QBE QUEL Datalog THE END