Download presentation
Presentation is loading. Please wait.
Published byDoreen Stanley Modified over 9 years ago
1
Understanding Relational Database Query Languages WinRDBI Windows-based Relational DataBase Interpreter http://winrdbi.asu.edu/ An educational tool that provides an interactive approach to learning relational database query languages. m Relational algebra m Domain Relational Calculus (DRC) m Tuple Relational Calculus (TRC) m SQL
2
Understanding Relational Database Query Languages WinRDBI Online Demonstrations Look for online demonstrations of the software on the WinRDBI web: http://winrdbi.asu.edu/ m Getting Started with WinRDBI m Creating a Database in WinRDBI Additional demonstrations will be added over time.
3
Understanding Relational Database Query Languages User Interface m Multiple Query Panes: one query language is associated with each pane; result of queries displayed in the bottom subwindow of the query pane m One Schema Pane: displays the schema and instance of the currently opened relational database
4
Understanding Relational Database Query Languages ICONS
5
Understanding Relational Database Query Languages Syntax Conventions Since the heart of WinRDBI is written in Prolog (with Java used for the graphical user interface), the following Prolog conventions are assumed: m constants: numeric constants and single-quoted strings m relation and attribute names: identifiers starting with a lowercase letter m variable names: identifiers starting with an uppercase letter
6
Understanding Relational Database Query Languages Relational Algebra Syntax Summary Fundamental Operators m (r) { t | t r and } m ai,…,aj (r) { t.ai, …, t.aj | t r } m r s { t | t r or t s } m r - s { t | t r and t s} m q × r { t q t r | t q q and t r r } Additional Operators m r s r - ( r - s ) m p q (p × q) m p q P Q ( (p × q) ) where = (p.ai=q.ai and … and p.aj=q.aj) P Q = {ai, …, aj} m p q P - Q (p) - P - Q (( P - Q (p) × q) - p)
7
Understanding Relational Database Query Languages Relational Algebra WinRDBI Syntax Summary WinRDBI m select condition (r) m project ai, …, aj (r) m r union s m r difference s m q product r m r intersect s m p njoin q : WinRDBI does not provide division and -join operators to encourage the use of the fundamental relational algebra operators. Formal Relational Algebra m condition (r) m ai,…,aj (r) m r s m r - s m q × r m r s m p q
8
Understanding Relational Database Query Languages Domain Relational Calculus Syntax Summary
9
Understanding Relational Database Query Languages Domain Relational Calculus Atoms & Formulas Let Di be a domain variable c be a domain constant be a comparison operator Atoms m r(D1, D2, …, Dn) m Di Dj m Di c FF1F2 Let F, F1 and F2 be formulas Formulas F ( F ) F not F F1F2 F1 and F2 F1F2 F F1 or F2 Let D be free* in F (D) F (exists D) F (D) F (forall D) F (D) * a variable is free in a formula if it is not quantified by exists or forall
10
Understanding Relational Database Query Languages Domain Relational Calculus Valid Expression
11
Understanding Relational Database Query Languages Domain Relational Calculus Relational Completeness condition (r): { R1, …, Rn | r(R1, …, Rn) and condition} ai,…,aj (r): { Ri, …, Rj | r(R1, …, Ri, …, Rj, …, Rn)} r s: { D1, …, Dn | r(D1, …, Dn) or s(D1, …, Dn) } r - s: { D1, …, Dn | r(D1, …, Dn) and not s(D1, …, Dn) } q × r : { Q1, …, Qm, R1, …, Rn | q(Q1, …, Qm) and r(R1, …, Rn) }
12
Understanding Relational Database Query Languages Tuple Relational Calculus Syntax Summary
13
Understanding Relational Database Query Languages Tuple Relational Calculus Atoms & Formulas Let T and Ti be tuple variables aj be an attribute c be a domain constant be a comparison operator Atoms m r(T) m Ti.am Tj.an m T.ai c FF1F2 Let F, F1 and F2 be formulas Formulas F ( F ) F not F F1F2 F1 and F2 F1F2 F F1 or F2 Let T be free* in F (T) F (exists T) F (T) F (forall T) F (T) * a variable is free in a formula if it is not quantified by exists or forall
14
Understanding Relational Database Query Languages Tuple Relational Calculus Valid Expression
15
Understanding Relational Database Query Languages Tuple Relational Calculus Relational Completeness condition (r): { R| r(R) and condition} ai…,aj (r): { R.ai, …, R.aj | r(R)} r s: { T | r(T) or s(T) } r - s: { T | r(T) and not s(T) } q × r : { Q, R | q(Q) and r(R) }
16
Understanding Relational Database Query Languages SQL Simple Query Syntax selectdistinct a1,…,am fromr1, r2, …, rn wherecondition is equivalent to a1,…,am ( condition (r1 × r2 × … × rn) )
17
Understanding Relational Database Query Languages SQL Relational Completeness m condition (r) m A (r) m r s m r - s m q × r m select * from r where condition m select distinct A from r m select * from r union select * from s m select * from r except select * from s m select * from q, r
18
Understanding Relational Database Query Languages SQL Query Syntax Summary select [distinct] ATTRIBUTE-LIST fromTABLE-LIST [whereWHERE-CONDITION] [group byGROUPING-ATTRIBUTES [havingHAVING-CONDITION]] [order byCOLUMN-NAME [asc | desc], … ]
19
Understanding Relational Database Query Languages SQL Data Definition Syntax Summary create table TABLE-NAME ( COL-NAME COL-TYPE [ATTR-CONSTRAINT], … [TABLE-CONSTRAINT-LIST] ) where ATTR-CONSTRAINT: not null or default value TABLE-CONSTRAINT-LIST: primary key, uniqueness and referential integrity (foreign key)
20
Understanding Relational Database Query Languages SQL Insert Syntax Summary insert into TABLE-NAME [ (ATTRIBUTE-LIST)] SOURCE where SOURCE is one of: m values ( EXPLICIT-VALUES) m SELECT-STATEMENT
21
Understanding Relational Database Query Languages SQL Update & Delete Syntax Summary update TABLE-NAME set COLUMN-NAME = VALUE-EXPR, … [whereUPDATE-CONDITION] delete from TABLE-NAME [whereDELETE-CONDITION]
22
Understanding Relational Database Query Languages SQL WinRDBI Syntax Summary Since WinRDBI has an integrated GUI for defining and manipulating the database, WinRDBI SQL supports only the query language. m SQL-89 compatibility: no joined tables in the from clause m Does not support SQL-standard view definition: assumes intermediate table syntax across all query languages m Language simplification disallows aggregation in a nested subquery: use two queries instead...
23
Understanding Relational Database Query Languages SQL Aggregation in Nested Queries SQL select E.eID, E.eLast, E.eFirst, E.eTitle from employee E where E.eSalary = (select min(S.eSalary) from employee S ); WinRDBI minimumSalary(minSalary) := select min(E.eSalary) from employee E; select E.eID, E.eLast, E.eFirst, E.eTitle from employee E where E.eSalary = (select minSalary from minimumSalary);
Similar presentations
© 2025 SlidePlayer.com Inc.
All rights reserved.