








































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
express a database query in Relational Algebra, involving the basic operators (selection, projection, cross product, renaming, set union, intersection,.
Typology: Summaries
1 / 48
This page cannot be seen from the preview
Don't miss anything!









































Unit 5 Laks V.S. Lakshmanan,;^ Based^ partly on^ Ramakrishnan^ &^ Gehrke, DB Management Systems 1
๏ฎ express a database query in Relational Algebra, involving the basic operators (selection, projection, cross product, renaming, set union, intersection, difference ), join, division and assignment
๏ฎ rewrite RA expressions (queries) using a subset of the operators with expressions using another subset
๏ฎ show that two RA queries are/arenโt equivalent
๏ฎ express a DB query in Datalog
๏ฎ translate RA queries to Datalog; translate queries from a fragment of Datalog to RA.
๏ฎ Procedural language
๏ฎ Basic operations:
๏ Selection - Selects a subset of rows from relation. ๏ Projection - Deletes unwanted columns from relation. ๏ Cross-product - Allows us to combine two relations. ๏ Set-difference - Tuples in reln. 1, but not in reln. 2. ๏ Union - Tuples in reln. 1 and tuples in reln. 2. ๏ Rename โ Assigns a(nother) name to a relation
๏ฎ Additional operations:
๏ intersection, join, division, assignment: not essential, but very useful
๏ฎ The operators take one or two relations as inputs and give a new relation as a result.
๏ ๐(๐ 1 , โฆ , ๐๐) where ๐ is a database relation. ๏ ๐ ๐๐ ๐ or ๐ ๐๐ ๐ where ๐, ๐ are variables and ๐ is a constant.
Set of tuples of r that satisfy p
๏ฎ Defined as:
Where p is a formula in propositional calculus consisting of predicates connectives : ๏ ( and ), ๏ ( or ), ๏ ( not ) A predicate is one of:
๏ก ๏ก ๏ข ๏ข
๏ก ๏ข ๏ข ๏ข
1 5 12 23
7 7 3 10
A B C D
๏ก ๏ข
๏ก ๏ข
1 23
7 10
RA (^) Datalog
attribute
variable
constant
cid cname rating salary 21 Y. Yuppy 5 95 50 B. Rusty 10 65 55 S. Sneezy 8 70
cname rating R. Rudy 9 G. Grumpy 8 S. Sneezy 5 R. Rusty 10
, Cust cname rating
salary 95 55
salary
7 ( , Cust cname rating rating ๏พ
cid cname rating salary 38 R. Rudy 9 95 32 G. Grumpy 8 55 51 S. Sneezy 5 95 78 R. Rusty 10 55 Cust
๏ฎ Defined as:
๏ฎ For these operations to be well-defined:
attributes)
๏ฎ What is the schema of the result?
Unit 5 16
Union,Int., Diff. Examples
cid cname rating salary
22 J. Justin 7 65 31 R. Rubber 8 85 58 N. Nusty 10 85 44 G. Guppy 5 70 28 Y. Yuppy 9 95
C 1 ๏ C 2
cid cname rating salary 31 R.Rubber 8 85 58 N. Nusty 10 85
C 1 ๏ C 2
cid cname rating salary 58 J. Justin 7 65
C 1 ๏ญ C 2
cid cname rating salary
22 J. Justin 7 65 31 R. Rubber 8 85 58 N. Nusty 10 85
cid cname rating salary 28 Y. Yuppy 9 95 31 R. Rubber 8 85 44 G. Guppy 5 70 58 N. Nusty 10 85
C 1 C 2
How do you write these queries in Datalog?
Unit 5 19
cid cname rating salary 22 J. Justin 7 65 31 R. Rubber 8 85 58 N. Nusty 10 85
cid iid day qty
22 101 10/10/0 6 10 58 103 11/12/0 6 5
Customer (^) Order
conflicting Customer x Order names
Customer .cid
sname rating salary Order. cid
iid day qty
22 J. Justin 7 65 22 101 10/10/96 10 22 J. Justin 7 65 58 103 11/12/96 5 31 R. Rubber 8 85 22 101 10/10/96 10 31 R. Rubber 8 85 58 103 11/12/96 5 58 N. Nusty 10 85 22 101 10/10/96 10 58 N. Nusty 10 85 58 103 11/12/96 (^52)
Attribute names present no issues for Datalog.
Unit 5 20
๏ฎ Allows us to name results of relational-algebra expressions. ๏ฎ Allows us to assign more names to a relation. ๏ฎ Allows us to rename attributes of a relation. ๏ฎ Notation
is as before, but it only renames attributes B1,โฆ,Bk of E to A1,โฆ,Ak.