Download presentation
Presentation is loading. Please wait.
Published byMelissa Barnett Modified over 9 years ago
1
Web Science & Technologies University of Koblenz ▪ Landau, Germany Relational Data Model
2
Steffen Staab staab@uni-koblenz.de Advanced Data Modeling 2 of 48 WeST Overview Relational data model; Tuples and relations; Schemas and instances; Named vs. unnamed perspective; Relational algebra;
3
Steffen Staab staab@uni-koblenz.de Advanced Data Modeling 3 of 48 WeST Table PlayerBirth Year Andy1980 Wim1975 Liam1985 Mike1988 Bert1971
4
Steffen Staab staab@uni-koblenz.de Advanced Data Modeling 4 of 48 WeST Observations The rows of the table contain pairs occurring in the relation player. There are two columns, labeled respectively by “name” and “birth year”. The values in each column belong to different domains of possible values.
5
Steffen Staab staab@uni-koblenz.de Advanced Data Modeling 5 of 48 WeST How to specify a relation 1.specifying the names of the columns (also called fields or attributes); 2. specifying a domain of possible values for each column; 3. enumerate all tuples in the relation. (1)–(2) refer to the schema of this relation, while (3) to an instance.
6
Steffen Staab staab@uni-koblenz.de Advanced Data Modeling 6 of 48 WeST Domains and attributes A set of domains (sets of values); A set of corresponding domain names d 1, d 2, … A set of attributes a 1, a 2, …
7
Steffen Staab staab@uni-koblenz.de Advanced Data Modeling 7 of 48 WeST Relation Schema and Instances Tuple: any finite sequence (v 1, …, v n ). n is the arity of this tuple. Relation schema: r(a 1 :d 1, …, a n :d n ) where n ¸ 0, r is a relation name, a 1, …, a n are distinct attributes, d 1, …, d n are domain names. Relation instance: finite set of tuples (v 1, …, v n ) of arity n such that v i 2 D i for all i.
8
Steffen Staab staab@uni-koblenz.de Advanced Data Modeling 8 of 48 WeST Observation 1.The attributes in each column must be unique. 2. A relation is a set. Therefore, when we represent a relation by a table, the order of rows in the table does not matter. Let us add to this: 3. The order of attributes does not matter.
9
Steffen Staab staab@uni-koblenz.de Advanced Data Modeling 9 of 48 WeST New notation for tuples A tuple is a set of pairs { (a 1, v 1 ), …, (a n, v n ) } denoted by { a 1 =v 1, …, a n =v n }, Let d 1, …, d n be domain names and be the corresponding domains. The tuple conforms to a relation schema r(a 1 :d1, …, a n :d n ) if v i 2 D i for all i.
10
Steffen Staab staab@uni-koblenz.de Advanced Data Modeling 10 of 48 WeST Relational data are structured Note that in the relational data model tuples stored in a table are structured: all tuples conform to the same relation schema; the values in the same column belong to the same domain. Untyped perspective: there is a single domain, so the second condition can be dropped.
11
Steffen Staab staab@uni-koblenz.de Advanced Data Modeling 11 of 48 WeST Typed or untyped? Consider the relation admire: admireradmired wimandy mikewim liamandy liamarsenal
12
Steffen Staab staab@uni-koblenz.de Advanced Data Modeling 12 of 48 WeST Database schema and instance Relational database schema: a collection of relation schemas with distinct relation names. Relational database instance conforming to a relational database schema S: a mapping I from the relation names of S to relation instances such that for every relation schema r(a 1 :d 1, …, a n :d n ) in S the relation instance I(r) conforms to this relation schema.
13
Steffen Staab staab@uni-koblenz.de Advanced Data Modeling 13 of 48 WeST Unnamed perspective No attributes a tuple is simply a sequence (v_1, …, v_n) of values. The components of tuples can therefore be identified by their position in the tuple.
14
Steffen Staab staab@uni-koblenz.de Advanced Data Modeling 14 of 48 WeST From Unnamed to Named Perspective Introduce a collection of attributes #1,#2, …, identify tuple (v 1, …, v n ) with the tuple { #1 = v 1, …,#n = v n }. Likewise, identify relation schema r(d 1, …, d n ) with r(#1:d 1, …,#n:d n ).
15
Steffen Staab staab@uni-koblenz.de Advanced Data Modeling 15 of 48 WeST Relational Algebra and SQL 1. Can define new relations from existing ones; 2. Uses a collection of operations on relations to do so.
16
Steffen Staab staab@uni-koblenz.de Advanced Data Modeling 16 of 48 WeST Constant { (v 11, …, v 1n ), ….. (v k1, …, v kn ) }
17
Steffen Staab staab@uni-koblenz.de Advanced Data Modeling 17 of 48 WeST Union R 1 [ R 2 = {(c 1, …, c k ) | (c 1, …, c k ) 2 R 1 or (c 1, …, c k ) 2 R 2 }
18
Steffen Staab staab@uni-koblenz.de Advanced Data Modeling 18 of 48 WeST Set difference R_1 - R2 = {(c 1, …, c k ) | (c 1, …, c k ) 2 R 1 and (c 1, …, c k ) 2 R 2 }
19
Steffen Staab staab@uni-koblenz.de Advanced Data Modeling 19 of 48 WeST Cartesian product R1 £ R2 = {(c 1, …, c k, d 1, …, d m ) | (c1, …, c k ) 2 R 1 and (d 1, …, d m ) 2 R 2 }.
20
Steffen Staab staab@uni-koblenz.de Advanced Data Modeling 20 of 48 WeST Projection Let now R be a relation of arity k and i 1, …, i m be numbers in {1, …, k}. ¼ i 1, …, i m (R) = {(c i 1, …, c i m ) | (c 1, …, c k ) 2 R }. We say that ¼ i 1, …, i m (R) is obtained from R by projection (on arguments i 1, …, i m ).
21
Steffen Staab staab@uni-koblenz.de Advanced Data Modeling 21 of 48 WeST Selection Assume formulas on domains with “variables” #1, #2, …. For example, #1 = #2. ¾ F (R) = {(c 1, …, c k ) | (c 1, …, c k ) 2 R and F holds on (c 1, …, c k )}.
22
Steffen Staab staab@uni-koblenz.de Advanced Data Modeling 22 of 48 WeST Overview Relational algebra, named perspective SQL Integrity constraints (Aggregates and grouping)
23
Steffen Staab staab@uni-koblenz.de Advanced Data Modeling 23 of 48 WeST Constant { { a 1 = v 11, …, a n = v 1n }, … …… { a 1 = v k1, …, a n = v kn } }
24
Steffen Staab staab@uni-koblenz.de Advanced Data Modeling 24 of 48 WeST Union Let R1, R2 be relations with the same attributes. R1 [ R2 = { t | t 2 R 1 or t 2 R 2 }
25
Steffen Staab staab@uni-koblenz.de Advanced Data Modeling 25 of 48 WeST Union, example AB ® 1 ® 2 ¯ 1 AB ® 1 ® 2 ¯ 1 ¯ 3 AB ® 2 ¯ 3 R1R1 R2R2 R 1 [ R 2
26
Steffen Staab staab@uni-koblenz.de Advanced Data Modeling 26 of 48 WeST Renaming Let R be a relation whose set of attributes is a 1,…,a n, c 1,…,c m Let b 1, …, b n be distinct attributes such that {b 1, …, b n } Å { c 1, …, c m } = ; Then ½ a 1 ! b 1, …, a n ! b n (R) = {{b 1 = v 1, …, b n =v n, c 1 =w 1, …, c m =w m } | {a 1 = v 1, …, a n =v n, c 1 =w 1, …, c m =w m } 2 R}
27
Steffen Staab staab@uni-koblenz.de Advanced Data Modeling 27 of 48 WeST 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: ¼ a 1,…, a n ( ¾ P (R 1 £ … £ R m )) The result of an SQL query is a relation. Exceptions?
28
Steffen Staab staab@uni-koblenz.de Advanced Data Modeling 28 of 48 WeST Integrity constraints Domain constraints. Key constraints. Foreign key constraints. More general, defined constraints. How to translate them?
29
Steffen Staab staab@uni-koblenz.de Advanced Data Modeling 29 of 48 WeST Query language Allow one to define: Relation and database schemas; Relations through our relations; Integrity constraints; Updates.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.