HW 1
HW 1
Amount REAL,
PRIMARY KEY(Name))
Customer_InterestedArtist:
CREATE TABLE Customer_InterestedArtist (Customer_name
CHAR(50),
Aritist_name
CHAR(50),
PRIMARY
KEY(Customer_name,
Aritist_name),
FOREIGN
KEY(Customer_name) REFERENCES Customer ON DELETE NO
ACTION, FOREIGN KEY(Aritist_name) REFERENCES Artist ON
DELETE NO ACTION)
Customer_InterestedGroup:
CREATE TABLE Customer_InterestedGroup (Customer_name
CHAR(50),
Group_name
CHAR(50),
PRIMARY
KEY(Customer_name,
Group
_name),
FOREIGN
KEY(Customer_name) REFERENCES Customer ON DELETE NO
ACTION, FOREIGN KEY(Group _name) REFERENCES Group ON
DELETE NO ACTION)
As the relationship between artistwork and group is many to many,
we could not put Group_name attribute in artistwork table. Thus, it
is impossible to ensure the total participation in the relationship as
there is no constraint can guarantee that every group tuple will be
in the artistwork_group table.
(temp1,
Book_id
(temp2,
Branch_id
NCH)))
(BOOK) ))
Branch_name=Sharpstown
(LIBRARY_BRA
No_of_copies
b. How many copies of the book titled The Lost Tribe are owned by
each library branch?
(temp1,
No_of_copies
Book_id
(BOOK) ))
(temp1 BOOK_COPIES)
c. Retrieve the names of all borrowers who do not have any books
checked out.
(temp1,
Card_no
(BOOK_LOANS)
BORROWER)
(temp2)
d. For each book that is loaned out from the Sharpstown branch and
whose Due_date is today, retrieve the book title, the borrowers
name, and the borrowers address.
(temp1,
Branch_id
Branch_name=Sharpstown
(LIBRARY_BRA
NCH)))
(temp3)
e. For each library branch, retrieve the branch name and the total
Branch_id, count()
(temp1))
(temp1))
(temp3, count>5(temp2))
Name, Address,Count
(temp3)
(temp1,
Branch_name=Central
Branch_id
LIBRARY_BRANCH) )
P
10
10
25
Q
a
a
a
R
5
5
6
A
10
10
25
B
b
b
c
C
6
5
3
P
15
15
Q
b
b
R
8
8
A
10
10
B
b
b
C
6
5
P
10
10
25
15
Q
a
a
a
b
R
5
5
6
8
A
10
10
25
NULL
B
b
b
c
NULL
C
6
5
3
NULL
P
15
15
NULL
Q
b
b
NULL
R
8
8
NULL
A
10
10
25
B
b
b
c
C
6
5
3
B
b
C
6
b.
c.
d.
e.
P
10
15
25
10
25
10
Q
a
b
a
b
c
b
R
5
8
6
6
3
5
f.
P
10
Q
a
R
5
A
10