is web

<is web>
Information Systems & Semantic Web
University of Koblenz ▪ Landau, Germany
Advanced Data Modeling
Relational Data Model continued
Steffen Staab
with
Simon Schenk
<is web>
Overview




Relational algebra, named perspective
Aggregates and grouping
SQL
Integrity constraints
ISWeb - Information Systems
& Semantic Web
Steffen Staab
[email protected]
2
<is web>
Constant
{ { a1 = v11, … , an = v1n },
…
…
…
{ a1 = vk1, … , an = vkn } }
ISWeb - Information Systems
& Semantic Web
Steffen Staab
[email protected]
3
<is web>
Union
Let R1, R2 be relations with the same attributes.
R1 [ R2 = { t | t 2 R1 or t2 R2 }
ISWeb - Information Systems
& Semantic Web
Steffen Staab
[email protected]
4
<is web>
Union, example
R1
R1 [ R2
R2
A
B
A
B
®
1
®
2
®
1
®
2
¯
3
®
2
¯
1
¯
1
¯
3
ISWeb - Information Systems
& Semantic Web
Steffen Staab
[email protected]
A
5
B
<is web>
Renaming
Let R be a relation whose set of attributes is a1,…,an, c1,…,cm
Let b1, … , bn be distinct attributes such that
{b1, … , bn} Å { c1, … , cm} = ;
Then
½a1!b1, … , an!bn(R) =
{{b1 = v1, … , bn=vn , c1=w1 , … , cm=wm} |
{a1 = v1, … , an=vn , c1=w1 , … , cm=wm} 2 R}
ISWeb - Information Systems
& Semantic Web
Steffen Staab
[email protected]
6
<is web>
Set difference
Let R1, R2 be relatations with the same attributes.
R1 – R2 = { t | t 2 R1 and t  R2}
ISWeb - Information Systems
& Semantic Web
Steffen Staab
[email protected]
7
<is web>
Set difference, example
R1
R2
R1 - R2
A
B
A
B
®
1
®
2
®
1
®
2
¯
3
¯
1
¯
1
ISWeb - Information Systems
& Semantic Web
Steffen Staab
[email protected]
A
8
B
<is web>
SQL
 SQL is based on set and relational operations with certain
modifications and enhancements
 A typical SQL query has the form:
select a_1, … , a_n
from R_1, … , R_m
where P
 This query is equivalent to relational algebra expression:
 ¼a1,…,an (¾P (R1£ … £ Rm))
 The result of an SQL query is a relation.
 Exceptions?
ISWeb - Information Systems
& Semantic Web
Steffen Staab
[email protected]
9
<is web>
Integrity constraints
 Domain constraints.
 Key constraints.
 Foreign key constraints.
 More general, defined constraints.
ISWeb - Information Systems
& Semantic Web
Steffen Staab
[email protected]
10
<is web>
Query language
Allow one to define:
 Relation and database schemas;
 Relations through our relations;
 Integrity constraints;
 Updates.
ISWeb - Information Systems
& Semantic Web
Steffen Staab
[email protected]
11