Union: | A ∪ B | = | {x | x∊A or x∊B} |
---|---|---|---|
Intersection: | A ∩ B | = | {x | x∊A and x∊B} |
Difference: | A – B | = | {x | x∊A and x∉B} |
Cartesian product: | A × B | = | {⟨a,b⟩ | a∊A, b∊B} |
---|
Union: | R ∪ S | = | {t | t∊R or t∊S} |
---|---|---|---|
Intersection: | R ∩ S | = | {t | t∊R and t∊S} |
Difference: | R – S | = | {t | t∊R and t∉S} |
Cartesian product: | R × S | = | {⟨x,y,u,v⟩ | ⟨x,y⟩∊R, ⟨u,v⟩∊S} |
Countries(name,capital,area,population,continent,currency)
name
(the primary key).
Output: the other attributes.
UsedIn(country,language)
country -> Countries.name
language -> Languages.code
CREATE TABLE Countries( country TEXT, capital TEXT, currency TEXT )
Countries(country:Text, capital:Text, currenct:Text)
country | capital | currency |
---|---|---|
Finland | Helsinki | EUR |
Estonia | Tallinn | EUR |
Sweden | Stockholm | SEK |
Countries =
[{country="Finland", capital="Helsinki", currency="EUR"),
{country="Estonia", capital="Tallinn", currency="EUR"},
{country="Sweden", capital="Stockholm", currency="SEK"}]
Order? no | Order? yes | |
---|---|---|
Duplicates? no | Set | Ordered set |
Duplicates? yes | Multiset | List or Array |
Countries(name,capital,area,population,continent,currency)
SELECT continent,currency FROM Countries;
SELECT DISTINCT continent,currency FROM Countries;
Concept | Rel Algebra | Set theory | SQL |
---|---|---|---|
domain (attribute values) | T | Type | |
relation | R | Table | |
cartesian product of sets | T1 × … × Tn | {⟨t1,…,tn⟩ | ti ∊ Ti} | table schema |
label | a | attribute name | |
component | t.a | ti(a) | value of attribute |
tuple | {a=t1,…,b=tn} | ⟨t1,…,tn⟩ | row |
{ti | ⟨…,ti,…⟩∊R} | column |
Concept | Rel Algebra | Set theory | SQL |
---|---|---|---|
union | R ∪ S | {t | t∊R or t∊S} | R UNION S |
intersection | R ∩ S | {t | t∊R and t∊S} | R INTERSECT S |
difference | R – S | {t | t∊R and t∉S} | R EXCEPT S |
Concept | Rel Algebra | Set theory | SQL |
---|---|---|---|
selection | σcR | {t | t∊R, C} | WHERE C |
projection | πa,b,cR | {⟨t.a,t.b,t.c⟩ | t∊R} | SELECT a,b,c |
cartesian product of relations | R × S | {⟨x,y,u,v⟩ | ⟨x,y⟩∊R, ⟨u,v⟩∊S} | FROM R, S |
theta join | R ⨝c S = σc(R × S) | R INNER JOIN S ON C | |
natural join | R ⨝ S | … | R NATURAL JOIN S |
Concept | Rel Algebra | Set theory | SQL |
---|---|---|---|
duplicates | δ R | DISTINCT | |
sorting | τa R | ORDER BY a |
Countries(country,capital,currency)
Countries(country,capital,currency)
CREATE TABLE Countries( country TEXT PRIMARY KEY, capital TEXT NOT NULL, currency TEXT NOT NULL);
CREATE TABLE Countries( country TEXT PRIMARY KEY, capital TEXT NOT NULL UNIQUE, currency TEXT NOT NULL);
Countries(country,currency,value)
country | currency | value |
---|---|---|
Finland | EUR | 1.09 |
Estonia | EUR | 1.09 |
Sweden | SEK | 0.12 |
|
|