Semi-structured data - exercises Exercise 1

advertisement
Exercise 1
• Represent the relations below using the OEM data
model.
Semi-structured data
exercises
C ities
R estaurants
R estaurants & C ities
1
2
Answer exercise 1 - the OEM model
DB
R es tau rants
T
T
6
r_ id
• Using the data model from the previous question,
formulate the following queries using Lorel:
C ities
3
T
5
1
R es tC ity
2
T
Exercise 2
7
r_ id
8
r_ id
nam e
nam e
nam e
14
16
18
4
T
T
9
r_ id
c _ id
10
r_ id
c _ id
street
T
r_ id
c _ id
street
– find all the restaurants that are located in Linkoping
T
11
12
c _ id
street
– find the address (city and street) of the “Hamlet” restaurant
c _ id
nam e
nam e
– list the restaurants by city (equivalent of GROUP BY)
H am let
N o rm and ie
M c D o n.
13
15
17
r1
r2
r3
21
S to rgatan
24
S t.L ars gatan
27
K ungs gatan
29
31
Linko p ing
N o rko p ing
28
c1
30
c2
3
Answer Exercise 2
4
Exercise 3
find all the restaurants that are located in Linkoping
select R.name
from DB.Restaurants.T R, DB.RestCities.T RC, DB.Cities.T C
where R.r_id = RC.r_id
and RC.c_id = C.c_id
and C.name = “Linköping”
• Write 4 simple queries in Lorel that illustrate the use of
coercion in the following types of comparison:
–
–
–
–
list the restaurants by city (equivalent of GROUP BY)
select C.name, (select R.name
from DB.Restaurants .T R, DB.RestCities.T RC
where R.r_id = RC.r_id
and RC.c_id = C.c_id)
from DB.Cities.T C
string type against integer type;
value against atomic object
value against complex object
value against set of objects
Explain how coercion works in each case
5
6
Exercise 4
Answer Exercise 4 - Strong Data Guide
• Draw the strong and the minimal Data Guides for
the restaurant guide data model below.
res taurant
41
res taurant
n earb y
42
n earb y
n earb y
c o ntac t
n am e
ad d res s c o ntac t
category name address
c atego ry
n am e
5
6
7
8
9
C h ef C h u
s treet
10
S aig o n
c ity
zip c o d e
11
M enlo P ark
m anag er
16
17
18
P alo A lto
9 23 10
nearby
12
13
fas t fo o d
S and ra
res erv atio n
14
19
20
p h o ne
26
27
28
29
7 1-72 -73
1 1-12 -13
3 1-32 -33
3 4-35 -36
21
48
49
address contact
50
51
city
zipcode reservation manager
street
city zipcode reservation manager
c ity zip c o d e res erv atio n m anag er
p h o ne
R y d s vagen
category name
47
15
street
s treet
contact
46
45
52
E l C am in o R eal
43
67
ad d res s c o ntac t
44
g o urm et
66
nearby
4
3
n am e ad d res s
cafe
c afe
2
c atego ry
Guide
restaurant
G uide
1
22
L in ko p ing
23
24
53
54
55
56
60
61
phone
phone
phone
phone
62
63
64
65
57
58
59
25
5 84 35
p h o ne
p h o ne
7
Answer Exercise 4 - Strong Data Guide continued
43
category name address
48
68
street
57
city
67
contact
name
69
70
73
address contact
74
zipcode reservation manager
58
59
41: 1
42: 2,3
43: 4
44: 5
45: 6,9
46: 7,10
47: 8, 11
48: 12
49: 13
50: 14
51: 15
52: 16
53: 17
54: 18
55: 19
nearby
nearby
66
71
75
reservation
61
8
56
phone
72
56: 20
57: 21
58: 22
59: 23
60: 24
61: 25
62: 26
63: 27
64: 28
65: 29
66: 3,4
67: 3
68: 9,13
69: 10,14
70: 11,15
71: 20,24
72: 27,28
73: 9
74: 10
75: 11
9
Answer Exercise 4 - Minimal Data Guide
• Using the data model and the data guides from the
previous question, formulate the following queries using
Lorel:
cafe
nearby
81
82
83
Exercise 5
Guide
80
restaurant
category name address
10
– find all the restaurants that are located near café Sandra
contact
84
85
– find all the restaurants that are on “Storgatan”
street city
86
87
reservation
zipcode
88
manager
89
phone
90
11
12
Download