instituto de matemática e estatística | ime-usp - instituto de ...jef/winrdbi.pdff describes the...

29
Understanding Relational Database Query Languages O que é WinRDBI O WinRDBI (Windows Relational DataBase Interpreter) é uma ferramenta educacional utilizada pela Universidade do Estado do Arizona, e que fornece uma abordagem ativa para entender as capacidades das seguintes linguagens de consulta para bancos de dados relacionais: Álgebra Relacional Cálculo Relacional de Domínio Cálculo Relacional de Tupla SQL O WinRDBI foi fundamentado na tecnologia de banco de dados dedutivos que utiliza a linguagem lógica Amzi! Prolog and Logic Server para consultar instâncias do banco de dados armazenadas como fatos lógicos e utiliza a API Swing Java para estabelecer a GUI. O WinRDBI pode ser executado tanto em Windows quanto em Linux.

Upload: others

Post on 25-Jul-2021

2 views

Category:

Documents


0 download

TRANSCRIPT

WinRDBIO que é WinRDBI
O WinRDBI (Windows Relational DataBase Interpreter) é uma ferramenta educacional utilizada pela Universidade do Estado do Arizona, e que fornece uma abordagem ativa para entender as capacidades das seguintes linguagens de consulta para bancos de dados relacionais:
– Álgebra Relacional – Cálculo Relacional de Domínio – Cálculo Relacional de Tupla – SQL
O WinRDBI foi fundamentado na tecnologia de banco de dados dedutivos que utiliza a linguagem lógica Amzi! Prolog and Logic Serverpara consultar instâncias do banco de dados armazenadas como fatos lógicos e utiliza a API Swing Java para estabelecer a GUI. O WinRDBI pode ser executado tanto em Windows quanto em Linux.
Understanding Relational Database Query Languages
Onde obter WinRDBI?
Understanding Relational Database Query Languages
Visão geral do WinRDBI
Vários recursos estão disponíveis para aprender o WinRDBI. Para começar, existem duas demonstrações em Flash que exibem o básico do que o WinRDBI pode fazer. Para assitir, clique nos links abaixo:
Introdução ao WinRDBI(approx 6 mins)
Criando um banco de dados com WinRDBI
Understanding Relational Database Query Languages
WinRDBI Windows-based Relational DataBase Interpreter
http://www.eas.asu.edu/~winrdbi
An educational tool that provides an interactive approach to learning relational database query languages.
Relational algebra
User Interface
Multiple Query Panes: one query language is associated with each pane; result of queries displayed in the bottom subwindow of the query pane
One Schema Pane: displays the schema and instance of the currently opened relational database
Understanding Relational Database Query Languages
ICONS
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:
constants: numeric constants and single-quoted strings
relation and attribute names: identifiers starting with a lowercase letter
variable names: identifiers starting with an uppercase letter
Understanding Relational Database Query Languages
Relational Algebra Syntax Summary
r ∪∪∪∪ s { t | t ∈ r or t ∈ s }
r - s { t | t ∈ r and t ∉ s}
q × r { t qtr | tq ∈ q and tr ∈ r }
Additional Operators r ∩∩∩∩ s
p θθθθ q σ θ (p × q)
p q πP ∪ Q( σ θ (p × q) ) where θ = (p.ai=q.ai and … and p.aj=q.aj) P ∩ Q = {ai, …, aj}
p ÷÷÷÷ q πP - Q (p) - πP - Q ((πP - Q (p) × q) - p)
Understanding Relational Database Query Languages
Relational Algebra WinRDBI Syntax Summary WinRDBI
selectcondition (r) project ai, …, aj (r) r union s r differences q product r r intersect s p njoin q : WinRDBI does not provide
division and θ-join operators to encourage the use of the fundamental relational algebra operators.
Formal Relational Algebra σcondition(r)
Relational Algebra WinRDBI Demo
Illustrate the features of the relational algebra language by example using the employee training enterprise that can be found at
http://www.prenhall.com/dietrich
{ D 1, …, Dn | FF (D1, …, Dn) }
F F describes the properties of the data to be retrieved.
The output schema of FF is given by the domain variables
D1, …, Dn that act as global variables in FF.
The result of the DRC expression gives the set of all tuples
(d1, d2, …, dn) such that when di is substituted for Di
(1 =< i =< n), FF is true.
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 r(D1, D2, …, Dn)
Formulas ( FF )
Let D be free* in FF(D)
(exists D) FF(D)
(forall D) FF(D) * a variable is free in a formula if it is not quantified by exists or forall
Understanding Relational Database Query Languages
Domain Relational Calculus Valid Expression
{ D 1, …, Dn | FF (D1, …, Dn) } is a valid DRC expression if it has only the variables appearing to the left of the vertical bar | free in FF. Any other variable appearing in FF must be bound.
free vs. bound variables
bound (free): variable is declared explicitly through quantification and its scope is the quantified formula
Understanding Relational Database Query Languages
Domain Relational Calculus Relational Completeness
σcondition (r):
πai,…,aj(r):
r ∪ s:
r - s:
q × r :
Understanding Relational Database Query Languages
Domain Relational Calculus WinRDBI Demo
Illustrate the features of the DRC language by example using the employee training enterprise that can be found at
http://www.prenhall.com/dietrich
{ T 1, …, Tn | FF (T1, …, Tn) }
F F describes the properties of the data to be retrieved.
The output schema of FF is given by the tuple variables
T1, …, Tn that act as global variables in FF.
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 r(T)
Formulas ( FF )
Let T be free* in FF(T)
(exists T) FF(T)
(forall T) FF(T) * a variable is free in a formula if it is not quantified by exists or forall
Understanding Relational Database Query Languages
Tuple Relational Calculus Valid Expression
{ T 1, …, Tn | FF (T1, …, Tn) } is a valid TRC expression if it has only the variables appearing to the left of the vertical bar | free in FF. Any other variable appearing in FF must be bound.
free vs. bound variables
bound (free): variable is declared explicitly through quantification and its scope is the quantified formula
Understanding Relational Database Query Languages
Tuple Relational Calculus Relational Completeness
σcondition (r):
q × r :
{ Q, R | q(Q) and r(R) }
Understanding Relational Database Query Languages
Tuple Relational Calculus WinRDBI Demo
Illustrate the features of the TRC language by example using the employee training enterprise that can be found at
http://www.prenhall.com/dietrich
SQL Simple Query Syntax
SQL Relational Completeness
select * from r union select * from s
select * from r except select * from s
select * from q, r
SQL Query 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)
Understanding Relational Database Query Languages
SQL Insert Syntax Summary
insert into TABLE-NAME [ (ATTRIBUTE-LIST)]
values ( EXPLICIT-VALUES)
update TABLE-NAME
SQL WinRDBI Syntax Summary
manipulating the database, WinRDBI SQL supports only
the query language.
Does not support SQL-standard view definition: assumes
intermediate table syntax across all query languages
Language simplification disallows aggregation in a nested
subquery: use two queries instead ...
Understanding Relational Database Query Languages
SQL Aggregation in Nested Queries
SQL
from employee E
from employee E
SQL WinRDBI Demo
Illustrate the features of the SQL language by example using the employee training enterprise that can be found at
http://www.prenhall.com/dietrich