INTRODUCTION TO RELATIONAL DATABASE SYSTEMS
DATENBANKSYSTEME 1 (INF 3131)
Torsten Grust Universität Tübingen Winter 2019/20
1
INTRODUCTION TO RELATIONAL DATABASE SYSTEMS DATENBANKSYSTEME 1 (INF - - PowerPoint PPT Presentation
INTRODUCTION TO RELATIONAL DATABASE SYSTEMS DATENBANKSYSTEME 1 (INF 3131) Torsten Grust Universitt Tbingen Winter 2019/20 1 CONSTRAINTS Recall the recent correlated SQL query returning the LEGO bricks in any of the animal-related
1
SELECT b.name FROM bricks b WHERE (SELECT c.name FROM categories c WHERE b.cat = c.cat) ~ 'Animal'
2
bricks piece type name cat weight img x y z 𝑑
categories cat name 𝑑₁ 𝑑ₙ
categories cat name 𝑑 𝑑
3
Pointer Value-based Reference points to address of object 𝑝 contains value that uniquely identifies target row 𝑝 is dangling contains value not found in target column ⚠ — contains value that is not unique in target column ⚠ is dereferenced query target table for the row containing the value
4
Value-based references between source table 𝑇 and target table 𝑈.
5
6
SELECT s.𝘣₁, …, s.𝘣ₖ □ SELECT t.𝑐₁, …, t.𝑐ₖ FROM 𝑇 s FROM 𝑈 t
7
ALTER TABLE [ IF EXISTS ] ‹source› ADD FOREIGN KEY (‹column_name› [, …]) REFERENCES ‹target› [ ON DELETE ‹action› ] [ ON UPDATE ‹action› ]
NO ACTION
CASCADE
SET NULL
8
[NOT] EXISTS(‹query›)
‹expression› [NOT] IN (‹query›)
9
SELECT s.𝘣₁, …, s.𝘣ₖ ⊈ SELECT t.𝑐₁, …, t.𝑐ₖ FROM 𝑇 s FROM 𝑈 t
EXISTS(SELECT 1 FROM 𝑇 s WHERE ROW(s.𝘣₁, …, s.𝘣ₖ) NOT IN (SELECT t.𝑐₁, …, t.𝑐ₖ FROM 𝑈 t))
10
tree node parent A ▢ B A C A D B E C F C
11
SELECT t2.node FROM tree t1, tree t2 WHERE t1.node = 'E' AND t1.parent = t2.parent
SELECT t3.node FROM tree t1, tree t2, tree t3 WHERE t1.node = 'A' AND t2.parent = t1.node AND t3.parent = t2.node
12
13
14