



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




Question 1: Entity Relational Model
a. Answers needed to relate data independence to the SALESPERSON table, e.g. "if the data in the salesperson table is stored in a file system, and not in a relational DBMS, if we added a new field to the salesperson table the application would have to be aware of it. But a relational database gives us data independence by providing a separation between the way the data is stored on the file and the way the application accesses it".
b. Cardinality = 4; degree = 4
c. Name the primary keys: Salesperson: Sid (region is also acceptable); Products Pid; Customers Cid; Orders <cid, pid>. Quantity is NOT a primary key (point was taken off if you indicated it as a primary key)
d. Orders has a foreign key Cid references customers, Pid references products. If you indicated that the Region attribute of Customers is a foreign key, referencing the Region key of Salesperson, that is also OK.
e. The only connection between any of the Entities and Salespersons is the Region attribute, between Customers & Salespersons, so we are looking for a relationship ("services") between Customers & Salespersons. If you drew the Salesperson entity correctly, you got 4 points. One more point if you underlined sid. Then points were taken off for not having the right relationship, or not having it correctly drawn. Below is one possible solution.
ORDERS
SALESPERSON
SERVICES
cid
cname Region Quantity Pname
Pprice pid
Cname
Sid
Quota
Region
Question 2
a. Maximum rotational delay:
1/7200 or 0.000139 sec We also take 99/100 * 1/
(1 point was taken off if you indicated the average rotational delay or ( * 1/7200))
Transfer rate:
512 * 100 * 7200 bytes/sec.
b. A slot directory is the on page data structure used to locate a variable length record on a page.
(A fix length record can also use a slot directory, if you explain how, you get credit.) There is a <record offset, record length> pair per slot in the slot directory when used in a variable length
record page. In a fix length record page, each slot has a flag indicating whether a particular slot is used or free.
Field offset refers to the offset from the beginning of a record, of a particular attribute (or field).
For instance, given the following schema: (sid: integer, name: char(30), grade: integer). The field offset of name should be 4 (since an int is 4 bytes.) Similarly the field offset of grade should be 34. (Note on
some implementations, fields in records are required to be word aligned so, you may actually get 36 as the field offset for grade.)
c. LRU and MRU have the same performance, both result in 5 page I/Os for the given paging sequence.
Some students forgot to count in the first 2 page accesses and put the number of I/Os for both algorithms as
may get only partial credit.
d. The problem is quite ambiguous. The ambiguity comes from two parts:
clock from the class homepage.
We give full credit to anyone with a reasonable analysis. Something we are particularly looking for is like:
your work you also received credit.)
Partial credit is given to any attempt that makes more or less sense.
Question 3
3.a1) Advantage of cluster index on sname: fast range search on sname field
1.5pts a2) Disadvantage: Any other indices on Salesperson would have to be unclustered, so range search on
those fields will be slow. Also there was overhead in maintaining the clustered property. 1.5pts a3) Nonclustered: When there is already a cluster index on SID or if range search on SID is more common 2 pts
Bob 152 Harry 152 Martha 831 Martha 131 Lin 255
Bob
1 point taken off if you had duplicates.
Question 5. SQL
a) List the names of the customers who have bought more than one item.
SELECT cname FROM customers WHERE cid IN (SELECT cid FROM orders GROUP BY cid HAVING count(*) > 1)
Alternative: HAVING sum(quantity) > 1)
Other possible solutions
SELECT cname FROM customers c, orders o1, orders o WHERE c.cid = o1.cid AND c.cid = o2.cid AND o1.pid <> o2.pid
SELECT c.cname FROM customers c, (SELECT cid FROM orders GROUP BY cid HAVING count (*) > 1) as o WHERE c.cid = o.cid
SELECT cname FROM customers WHERE 1 < (SELECT count(*) FROM orders o WHERE c.cid = o.cid)
e) List the names, pid, and price of all the products, whether or not the product has been ordered, but if it
has been ordered display the cids of the customer who ordered it.
Solution 1:
SELECT name, pid, price, cid FROM products LEFT OUTER JOIN orders ON products.pid = orders.pid <<<< optional
Solution 2:
SELECT name, p.pid, price, cid FROM products p, orders o WHERE p.pid = o.pid UNION SELECT name, pid, price, NULL as cid FROM products p WHERE cid NOT IN (SELECT cid FROM orders)
Alternatives: WHERE NOT EXISTS (SELECT * FROM orders o WHERE o.pid = p.pid) WHERE cid <> ANY (SELECT cid FROM orders)
f) List the names and cids of all customers, and, for those who have bought product, the total amount of money they owe for their purchases.
Solution 1:
SELECT c.name, c.cid, total = sum(price * quantity) FROM customers c, orders o, products p WHERE c.cid = o.cid AND o.pid = p.pid GROUP BY c.name, c.cid UNION SELECT c.name, c.cid, totoal = NULL FROM customers c WHERE c.cid NOT IN (SELECT cid FROM orders)
Solution 2:
SELECT name, cid total = sum(price * quantity) FROM costomer LEFT OUTER JOIN (orders INNER JOIN products)