CS610/710 Assignment 1

advertisement
CS610/710 Exercise 1
1. Consider a university database for the scheduling of classrooms for final exams. This
database has the following entity sets:
i. COURSE with attributes NAME, DEPARTMENT, COURSE_NUMBER
ii. SECTION with attributes SECTION_NUMBER, ENROLLMENT
iii. ROOM with attributes ROOM_NUMBER, CAPACITY, and BUILDING
Design an entity-relationship diagram to represent this scheme, assuming appropriate
relationships between the entity sets.
2. For the entity-relationship diagram below, design suitable relation schemas in the relational
model. Determine and underline the keys in the relation schemas.
model
ss#
name
year
address
person
owns
driver
date
license
car
log
damage amount
accident
3. Consider the relations below:
A
a
a
b
e
e
a
B
C
b
c
b
e
c
e
d
c
d
e
d
d
Relation R
D
d
f
f
d
f
e
C
c
e
D
d
f
Relation S
Compute the following relational algebra expression using the set rules:
 A,B(R) - A,B((  A,B(R) X S) - R)
4. Consider the relations below:
branch-name
Downtown
Mianus
Perryridge
Round Hill
Perryridge
Redwood
Brighton
Downtown
account-number customer-name
101
Johnson
215
Smith
102
hayes
305
Turner
201
Williams
222
Lindsay
217
Grossman
105
Grossman
Figure 4.1 The deposit relation
balance
500
700
400
350
900
700
750
850
customer-name
street
customer-city
Jones
Main
Harrison
Smith
North
Rye
Hayes
Main
Harrison
Curry
North
Rye
Lindsay
Park
Pittsfield
Turner
Putnam
Stamford
Williams
Nassau
Princeton
Adams
Spring
Pittsfield
Johnson
Alma
Palo Alto
Green
Sand Hill
Woodside
Brooks
Senator
Brooklyn
Grossman
Walnut
Stamford
Firugre 4.2 The customer relation
branch-name
Downtown
Redwood
Perryridge
Downtown
Mianus
Round Hill
Pownal
North Town
Downtown
Perryridge
Brighton
loan-number
17
23
15
14
93
11
29
16
18
25
10
customer-name
Jones
Smith
Hayes
Jackson
Curry
Turner
Williams
Adams
Johnson
Green
Brooks
amount
1000
2000
1500
1500
500
900
1200
1300
2000
2500
2200
Figure 4.3 The borrow relation
branch-name
Downtown
Redwood
Perryridge
Mianus
Round Hill
Pownal
North Town
Brighton
assets
branch-city
9000000
Brooklyn
2100000
Palo Alto
1700000
Horseneck
400000
Horseneck
8000000
Horseneck
300000
Bennington
3700000
Rye
7100000
Brooklyn
Figure 4.4 The branch relation
Compute each of the following relational algebra expressions using the set rules and explain in
English what they mean.
a.
customer-name, customer-city(borrow
customer)
b.
 customer-name(deposit) -  customer-name((  customer-name(deposit) X (  branch-name(branchcity=Brooklyn(branch)))) -  customer-name, branch-name(deposit))
Also, compute the above two expressions using the bag rules.
5. Exercise 5.3.5 part b and c in the text.
The following algebraic laws hold for sets but not for bags. Explain why they hold for sets and
give counterexamples to show that they do not hold for bags.
a) The distributive law of intersection over union: R (ST) = (RS)(RT)
b) C OR D(R) = C(R)  D(R). Here, C and D are arbitrary conditions about the tuples of R.
6. Consider a database of suppliers (S), parts (P), and projects (J), which are uniquely identified
by supplier number (S#), part number (P#), and project number (J#), respectively. An
additional shipment (SPJ) relation is used to indicate that the specified supplier supplies the
specified part to the specified project in the specified quantity (and the combination S#-P#-J#
uniquely identifies such a tuple). An example extensional database is:
S
S#
S1
S2
S3
S4
S5
SNAME
Smith
Jones
Blake
Clark
Adams
STATUS
20
10
30
20
30
P
P#
P1
P2
P3
P4
P5
P6
PNAME
Nut
Bolt
Screw
Screw
Cam
Cog
COLOR
Red
Green
Blue
Red
Blue
Red
J
J#
J1
J2
J3
J4
J5
J6
J7
JNAME
Sorter
Display
OCR
Console
RAID
EDS
Tape
CITY
Paris
Rome
Athens
Athens
London
Oslo
London
CITY
London
Paris
Paris
London
Athens
WEIGHT
12
17
17
14
12
19
SPJ
CITY
London
Paris
Rome
London
Paris
London
S#
S1
S1
S2
S2
S2
S2
S2
S2
S2
S2
S3
S3
S4
S4
S5
S5
S5
S5
S5
S5
S5
S5
S5
S5
P#
P1
P1
P3
P3
P3
P3
P3
P3
P3
P5
P3
P4
P6
P6
P2
P2
P5
P5
P6
P1
P3
P4
P5
P6
J#
J1
J4
J1
J2
J3
J4
J5
J6
J7
J2
J1
J2
J3
J7
J2
J4
J5
J7
J2
J4
J4
J4
J4
J4
QTY
200
700
400
200
200
500
600
400
800
100
200
500
300
300
200
100
500
100
200
100
200
800
400
500
Define the following predicates using safe Datalog rules:
a.
nonlocalProjects(J#) that is true if the project specified by J# is supplied by at least one supplier not
in the same city.
b.
partPairs(P#1, P#2) that is true if some supplier suppliers both part P#1 and P#2.
c.
noRedLondoners(J#) that is true if project J# is not supplied with any red part by any London
supplier,
d.
londonParts(p#) that is true if part P# is supplied to all projects in London.
7. Write each of the queries of the previous exercise in relational algebra.
8. Consider the rules
p(X)  r(X) & s(X).
p(X)  t(X, Y) & p(Y).
q(X)  r(X) & p(X).
q(X)  t(X, Y) & q(Y).
Suppose the EDB predicates r, s, and t have, respectively, the relations R = {2, 3}, S = {2}, and
T = {(1, 1), (2, 2), (3, 3), (4, 4), (2, 1), (3, 2), (4, 3)}
Find, for the IDB predicates p and q:
a.
The least fixed point.
b.
Another minimal fixed point.
c.
A fixed point that is not minimal.
Hint: For the value of T given, we can think of the second rule as saying “if p(i) is true, then p(j) is true for
all j, i  j  4”, and we can understand the fourth rule similarily.
Download