|
Solutions for Section 4.2
Solutions for Section 4.3
Solutions for Section 4.4
Solutions for Section 4.5
Solutions for Section 4.6
Solutions for Section 4.7
class Customer { attribute string name; attribute string addr; attribute string phone; attribute integer ssNo; relationship Set<Account> ownsAccts inverse Account::ownedBy; } class Account { attribute integer number; attribute string type; attribute real balance; relationship Set<Customer> ownedBy inverse Customer::ownsAccts }
class Person { attribute string name; relationship Person motherOf inverse Person::childrenOfFemale relationship Person fatherOf inverse Person::childrenOfMale relationship Set<Person> children inverse Person::parentsOf relationship Set<Person> childrenOfFemale inverse Person::motherOf relationship Set<Person> childrenOfMale inverse Person::fatherOf relationship Set<Person> parentsOf inverse Person::children }Notice that there are six different relationships here. For example, the inverse of the relationship that connects a person to their (unique) mother is a relationship that connects a mother (i.e., a female person) to the set of her children. That relationship, which we call childrenOfFemale, is different from the children relationship, which connects anyone -- male or female -- to their children.
class Customer (extent Customers key ssNo) { attribute string name; attribute string addr; attribute string phone; attribute integer ssNo; relationship Set<Account> ownsAccts inverse Account::ownedBy; } class Account (extent Accounts key number) { attribute integer number; attribute string type; attribute real balance; relationship Set<Customer> ownedBy inverse Customer::ownsAccts }
Customers(ssNo, name, address, phone) Accounts(number, type, balance) CustAcct(ssNo, number)
Persons(name, childrenOfFemale, childrenOfMale) Parent-Child(parent, child)
Studios(name, address, ownedMovie)
Since name -> address is the only FD, the key is {name, ownedMovie}, and the FD has a left side that is not a superkey.
(a) Struct Card { string rank, string suit }; (b) class Hand { attribute SettheHand; };
For part (c) we have:
Hands(handId, rank, suit)
Notice that the class Hand has no key, so we need to create one: handID. Each hand has, in the relation Hands, one tuple for each card in the hand.
Struct PlayerHand { string Player, Hand theHand }; class Deal { attribute SettheDeal; }
Alternatively, PlayerHand can be defined directly within the declaration of attribute theDeal.
Deals(dealID, player, handID) Hands(handID, rank, suit)
However, if we think about it, we can get rid of handID and connect the deal and the player directly to the player's cards, as:
Deals(dealID, player, rank, suit)
Deals(dealID, handID, rank, suit)
C(a, f, g, count)
Studios(name, address, movies{(title, year, inColor, length, stars{(name, address, birthdate)})})
Since the information about a star is repeated once for each of their movies, there is redundancy. To eliminate it, we have to use a separate relation for stars and use pointers from studios. That is:
Stars(name, address, birthdate) Studios(name, address, movies{(title, year, inColor, length, stars{*Stars})})Since each movie is owned by one studio, the information about a movie appears in only one tuple of Studios, and there is no redundancy.
Customers(name, address, phone, ssNo, accts{*Accounts}) Accounts(number, type, balance, owners{*Customers})
To represent ownership of accounts by customers, we place an arc labeled owns from each customer node to the node of each account that customer holds (possibly jointly). Also, we place an arc labeled ownedBy from each account node to the customer node for each owner of that account.
<STARS-MOVIES> <STAR starId = "cf" starredIn = "sw, esb, rj"> <NAME>Carrie Fisher</NAME> <ADDRESS><STREET>123 Maple St.</STREET> <CITY>Hollywood</CITY></ADDRESS> <ADDRESS><STREET>5 Locust Ln.</STREET> <CITY>Malibu</CITY></ADDRESS> </STAR> <STAR starId = "mh" starredIn = "sw, esb, rj"> <NAME>Mark Hamill</NAME> <ADDRESS><STREET>456 Oak Rd.<STREET> <CITY>Brentwood</CITY></ADDRESS> </STAR> <STAR starId = "hf" starredIn = "sw, esb, rj, wit"> <NAME>Harrison Ford</NAME> <ADDRESS><STREET>whatever</STREET> <CITY>whatever</CITY></ADDRESS> </STAR> <MOVIE movieId = "sw" starsOf = "cf, mh"> <TITLE>Star Wars</TITLE> <YEAR>1977</YEAR> </MOVIE> <MOVIE movieId = "esb" starsOf = "cf, mh"> <TITLE>Empire Strikes Back</TITLE> <YEAR>1980</YEAR> </MOVIE> <MOVIE movieId = "rj" starsOf = "cf, mh"> <TITLE>Return of the Jedi</TITLE> <YEAR>1983</YEAR> </MOVIE> <MOVIE movieID = "wit" starsOf = "hf"> <TITLE>Witness</TITLE> <YEAR>1985</YEAR> </MOVIE> </STARS-MOVIES>
<!DOCTYPE Bank [ <!ELEMENT BANK (CUSTOMER* ACCOUNT*)> <!ELEMENT CUSTOMER (NAME, ADDRESS, PHONE, SSNO)> <!ATTLIST CUSTOMER custId ID owns IDREFS> <!ELEMENT NAME (#PCDATA)> <!ELEMENT ADDRESS (#PCDATA)> <!ELEMENT PHONE (#PCDATA)> <!ELEMENT SSNO (#PCDATA)> <!ELEMENT ACCOUNT (NUMBER, TYPE, BALANCE)> <!ATTLIST ACCOUNT acctId ID ownedBy IDREFS> <!ELEMENT NUMBER (#PCDATA)> <!ELEMENT TYPE (#PCDATA)> <!ELEMENT BALANCE (#PCDATA)> ]>