Vous êtes sur la page 1sur 28

Question 1 Find the relational tables that correspond to the E-R diagram in Figure 1. Use as few tables as possible.

For each relation, underline the primary key completely and list all foreign keys clearly on the side or by arrows.

Name SSN

Address

father

Customer
children
N Items-in-will 1

father-of

Related-to
1

Relationship

Beneficiary

Name

Address

Figure 1: E-R diagram

Answer 1 Relational schema: Customer(SSN, Name, Address, FatherSSN ) Foreign key FatherSSN refers to SSN of Customer Beneciary( CSSN, Name, Address, Relationship ) Foreign key CSSN refers to SSN of Customer Items(CSSN, Name, ItemName ) Foreign key CSSN+Name refers to the same in Beneciary Items should be a dierent relation since you cannot store multiple values for an attribute (i.e. sets) in relations.

Question 2 Map the E-R diagram in Figure 2 into a relational schema. Specify all primary keys and foreign keys.

Branch-name

Branch-city

assets

address SSN name

BRANCH

N Loan-branch 1
Loan-number

CUSTOMER
1 Cust-banker N

borrower

LOAN
amount

type

Loan-payment N Works_for N 1

manager worker

EMPLOYEE

PAYMENT

ESSN Employment-length Dependent-name

name Payment# Phone# Start-date Payment_date Payment_amount

Figure 2: E-R diagram

Answer 2 The relation model is given below: Customer(SSN, Name, Address, Cust Banker) Primary Key(SSN), Foreign Key Cust Banker references Employee(SSN) Branch(Branch Name, Branch City, Assets) Primary Key(Branch Name) Employee(ESSN, Employment Length, Start Date, PhoneNo, Name) Primary Key(ESSN) EmployeeDependent(ESSN,Dependent Name) Primary Key(ESSN, Dependent Name), Foreign key ESSN references Employee(ESSN), WorksFor(Manager, Worker) Primary Key(Manager, Worker), Foreign Key Manager references Employee(SSN), Foreign Key Worker references Employee(SSN) Loan(Loan Number, Amount, BorrowerSSN, Loan Branch) Primary Key(Loan Number), Foreign Key BorrowerSSN references Employee(SSN), Foreign Key Loan Branch references Branch(Branch Name) Payment(Loan Number, PaymentNo, Payment Date, Payment Amount) Primary Key (Loan Number, PaymentNo), Foreign Key Loan Number references Loan(Loan Number)

Question 3 Find the equivalent relational schema for the diagram in Figure 3.

EID

Ename

supervisor

Employee
supervisee
N

Supervises
1

Title

Works-for
Dname

Locations

Department
N

Directs

Project

DID

Owns
1

Expiration Date

PID

Classification

Resource

ResID

Description

Figure 3: E-R diagram

Answer 3 Relational schema: Employee ( EID, Ename, SuperID, Title ) /* SuperID is a foreign key to Employee.EID Department ( DID, Dname ) Department Locations( DID, Location ) Works For ( EID, DID ) Resource ( ResID, DID, Description, Expiration Date) Project ( PID, Classication, DID ) /* DID is a foreign key to Department.DID Note that the above is not a good database design since there exist two functional dependencies in Employee, namely {EID} {Ename, SuperID, Title} {SuperID} {Title} This relation is in 2NF, but not 3NF. To make it 3NF, we decompose it into: Employee( EID, Ename, SuperID ) Supervisor ( SuperID, Title ) In the original design, we would have to make sure all title attributes for a single supervisor are the same with respect to all employees that they supervise.

Question 4 You are given the E-R diagram in Figure 4. Convert this into an equivalent relational schema. Mark primary keys for each relation and the foreign keys if there are any.

StoreID

StoreName

Store

Belongs_to

Chain

Sells
N
Stock_qty

ChainName

Product

ProductID

Product_Name

Figure 4: E-R diagram

Answer 4 The relational model is given below: Store(StoreId, StoreName, ChainName) Primary Key(StoreId), Foreign Key ChainName references Chain(ChainName) Product(ProductId, Product Name) Primary Key(ProductId) Chain(ChainName) Primary Key(ChainName) Sells(StoreId, ProductId) Primary Key(StoreId, ProductId), Foreign Key StoreId references Store(StoreId), Foreign Key ProductId references Product(ProductId)

Question 5 Suppose you are constructing a database for a radio station. Your database is going to store the CDs your station owns and also the program information about broadcasts of your station. You will store the following pieces of information: Assume you are given entities for songs, musicians, CDs and labels. For broadcasters, you will store the name of radio personalities and other relevant information. For shows, you will store the title, format, air date and time of dierent shows. Broadcasters usually have a number of shows they produce periodically. At each specic airing of a show, there is a play list which contains a number of songs from specic CDs in a particular order. Draw an entity-relationship diagram for your database. You can use the E-R diagram from Question 1 as part of your database or introduce a modied version of it. Choose 2-4 attributes for each entity. Show all entities, relationships and attributes clearly. Clearly mark identiers and the cardinalities of all relationships. If you make any assumptions about your database design, state them clearly. Note: If you are using entities songs, musicians, CDs or labels in the solution, you do not have to show any attributes for these entities.

Answer 5 In this sample answer, the term broadcasters refers to the radio personalities, i.e. people. Shows are periodical, they appear at certain days and times. At a specic airing of a show, there is a playlist, which is the list of songs played on that day, obtained from the contain relationship. We allow each show to be produced by exactly one show, and only one show to be aired at a given date and time. Note that, for the airings entity date and time together is the key.

id name

address salary name format

BROADCASTERS

produce

SHOWS
N

SONGS

have contain

order

AIRINGS

CDS
date time

Figure 5: E-R diagram

Question 6 You are asked to construct a database for managing the X-Files, i.e. criminal case descriptions and the people who were involved in these cases. A partial data model for the X-Files database is given below: Part 1. Convert the entity-relationship diagram in Figure 6 into a corresponding relational schema. List all tables. In each table, underline the primary identier. If a specic attribute is a foreign key to another relation, write a short note indicating this. Use as few tables as possible.

LastName FBI-ID StartDate Name

FirstName Fileno Rank PeopleInvolved CaseLocation Description

Works-on

AGENTS
N

X-FILES

Involved-in

NEWSPAPER ARTICLES

CONSPIRATORS
ArticleNo Date CodeName Name Newspaper

Text

LastName

FirstName

Figure 6: ER diagram

Part 2. Add the following relationships to the entity relationship diagram in Part 1. Indicate the cardinalities clearly for all relationships. A conspirator may be the father of one or more agents. Each X-File may be the subject of one or more newspaper articles. Each article may refer to multiple X-File cases. An X-File case may be related to another X-File case. The follow-up relationship indicates that an X-File may follow at most one earlier case, while a case may be followed by many new cases.

Answer 6 Sample answer: Part 1. AGENTS( FBI-ID, StartDate, LastName, FirstName, Rank ) X-FILES( Fileno, CaseLocation, Description, Agent1, Agent2 ) XFILE-PEOPLEINVOLVED( Fileno,personinvolved ) NEWSPAPERARTICLES( ArticleNo, Date, Newpaper, Text ) CONSPIRATORS( CodeName, Lastname, FirstName) INVOLVED-IN( ConspiratorName, XleNo ) Agent1 and Agent2 attributes in the X-FILES table are both foreign keys to the FBI-ID attribute of the AGENTS table. Fileno attribute in the XFILE-PeopleInvolved relation is a foreign key that refers to the Fileno attribute of the XFILE table. ConspiratorName attribute in the INVOLVED-IN table is a foreign key that refers to the CodeName attribute of the CONSPIRATORS table. XleNo attribute in the INVOLVED-IN table is a foreign key that refers to the Fileno attribute of the XFILES table. Part 2. The new relationships are shown in the Figure 7. Assumptions: we only consider birth fathers, hence everybody has a single father. Newspaper articles that do not refer to any X-Files may still exist in the database.

AGENTS
1

X-FILES
N

Follows Followed-by

Follow
N

Father-of

Subject-of
N

CONSPIRATORS

NEWSPAPER ARTICLES

Figure 7: E-R diagram

Question 7 This question has two parts: Part 1. You are given the E-R diagram in Figure 8. Add the following relationships to this diagram and mark the cardinalities of each relationship clearly. HAVE-ACCOUNT: people have credit card accounts. Each credit card account has to have one or more people who owns that account. One person may have none, one or many credit accounts. SPONSOR-ACCOUNT: stores sponsor credit card account. Each store may have none, one or more accounts. Each credit card may be sponsored by at most one store. PUBLISH: stores publish catalogs. Each catalog has to belong to a store and each store may publish at most one catalog. A store may not publish a catalog at all. Part 2. Convert the E-R diagram you constructed in Part 1 into the corresponding relational schema. List all tables. In each table, underline the primary identier. If a specic attribute is a foreign key to another relation, write a short note indicating this. Use as few tables as possible.

SSN

LastName FirstName Address ID

Name Location

PEOPLE

STORES

CREDIT CARD

CATALOG

Number

ExpirationDate

Name

Date_of_Pub

Name

CreditLimit

Figure 8: E-R diagram

10

Answer 7 The relational data model corresponding to this E-R diagram is given below: People(SSN, FirstName, LastName, Address) Primary Key(SSN,LastName, Address) Stores(Id, Name) Primary Key(Id) StoreLocation(Id, Location) Primary Key(Id, Location), Foreign Key Id references Stores(Id) CreditCard(Number, Name, CreditLimit, ExpirationDate, SponsorStore) Primary Key(Number), Foreign Key SponsorStore references Stores(Id) Catalog(Name, DateOfPub, StoreId) Primary Key(Name), Foreign Key StoreId references Stores(Id) HasCard(SSN, LastName, Address, Number) Primary Key(SSN, LastName, Address, Number), Foreign Key (SSN, LastName, Address) references People(SSN, LastName, Address), Foreign Key Number references CreditCard(Number)

PEOPLE

STORES

sponsor hasCard sponsor

CREDIT CARD

CATALOG

Figure 9: E-R diagram

11

Question 8 Map the Entity-Relationship diagram in Figure 10 into a relational database. Show the relations that would be in this database. For each relation, identify the primary key and any foreign keys.

name make

SSN

address

id

Person

owns

Car
1

insures
N
premium

Insurance Company

name

address

Figure 10: ER diagram

Answer 8 Relational schema: Person(ssn, name, address) Car(id, make, insureCoName, premium) InsuranceCompany(name, address) Owns(ssn, id ) Primary keys underlined and foreign keys is emphasized.

12

Question 9 You are given a preliminary data model for a library. It consists of the following entities: BOOKS correspond to dierent books with a unique ISBN number. PUBLISHERS correspond to dierent publishing houses, with given name and address. AUTHORS correspond to dierent people who appear as authors with name, and birth date. COPIES correspond to individual copies of books. Each copy has a unique id. Draw these entities as an entity relationship diagram. Do not add any attributes to the entities. Add the following information as relationships with associated attributes and mark the cardinalities very carefully to enforce the following constraints whenever possible: 1. Authors write or edit books. Each book may have many authors and authors may write many books. 2. Publishers publish books, each book has a single publisher. 3. Each copy is of a book. In fact, copy is a weak entity that depends on the book entity by a copy-of relationship. 4. Each author is aliated with a publisher at a given year. At any year, each author is aliated with a single publisher. 5. A book may be a new edition of an existing book. Each book can be the new edition of a single book. Answer 9 Note that Role in the WriteEdit relationship takes values of the form Author or Editor.

BOOKCOPY

PUBLISHER

1 N
CopyOf NewEdition

N next edition 1 previous edition

Publishes

N BOOK N

1 AUTHOR

N
WriteEdit

Role

Figure 11: ER diagram

13

Question 10 You are given the following simple database of employees that work in specic departments. Each department has an inventory of items with specic quantity. EMPLOYEE(ssn, rst-name, last-name, address, date-joined, supervisor-ssn) DEPARTMENT(dept-no, name, manager-ssn) WORKS-IN(employee-ssn, dept-no) INVENTORY(dept-no, item-id, quantity) ITEMS(item-id, item-name, type) Foreign keys: 1. EMPLOYEE.supervisor-ssn and WORKS-IN.employee-ssn point to EMPLOYEE.ssn. 2. WORKS-IN.dept no and INVENTORY.dept-no point to DEPARTMENT.dept no. 3. INVENTORY.item-id points to ITEMS.item-id. Assume in the above model that the key is unique for all relations. For example, two items with dierent id are considered dierent items. Furthermore, any attribute that is not part of a key can be null. According to the data model above: 1. Can employees work in more than one department? 2. Can departments have more than one manager? 3. Can a dierent departments have the same item-id in their inventory? 4. Do employees have to work in the same department as their supervisor? Explain your answers briey by giving reasons from the relational data model. Answer 10 The answers are below. 1. Can employees work in more than one department? Yes, it is possible to have two tuples of the form: WORKS-IN(E1,D1), WORKS-IN(E1,D2) since the primary key includes both attributes. 2. Can departments have more than one manager? No, due to the primary key of the DEPARTMENT relation, there is at most one tuple for each department and only one manager information can be stored in a single tuple. 3. Can dierent departments have the same item-id in their inventory? Yes, it is possible to have two tuples with the same item-id, but dierent department numbers because the primary key includes both attributes. 4. Do employees have to work in the same department as their supervisor? No, there is no constraints that links the department of the employee with that of the manager.

14

Question 11 You are given the diagram in Figure 12 for storing information about a virtual store containing various items from dierent stores. Convert this entity relationship diagram to a relational database. For each relation, show the primary keys, list the foreign keys and write down which attribute they point to.

color

Soldwith
N N item 1
name

size

group

Belong_to
N super

name description

ITEMS
N

CATEGORIES
sub N

Subcat

price

Soldby

Buy
N N

Prefer

priority

STORES

USERS

ID name

location

ID name

phone

Figure 12: E-R diagram

15

Answer 11 Relational schema: ITEMS(name, description, price, category) ITEMS.category refers to CATEGORIES.name ITEMCOLORS(itemname, color) ITEMCOLORS.itemname refers to ITEMS.name ITEMSIZES(itemname, size) ITEMSIZES.itemname refers to ITEMS.name SOLDWITH(item1, item2) SOLDWITH.item1, SOLDWITH.item2 both refer to ITEMS.name CATEGORIES(name, sup category) CATEGORIES.sup category refers to CATEGORIES.name STORES(id, name, location) SOLDBY(itemname, storeid) SOLDBY.itemname refers to ITEMS.name, SOLDBY.storeid refers to STORES.id USERS(id, name, phone, cat1, priority1, cat2, priority2) USERS.cat1, USERS.cat2 both refer to CATEGORIES.name BUY(itemname, userid) BUY.itemname refers to ITEMS.name, BUY.userid refers to USERS.id Note. According to this model, if a person buys the same item more than once, there will be a single record of it! It is a design limitation.

16

Question 12 In this question, you are asked to create an entity-relationship diagram for an auction house. In this database, people register as buyers and/or owners, post items, and place bids on items. First decide on the primary entities in your database and draw the major relationships between the entities. Then, add the necessary attributes for entities and relationships either on your graph or list them separately. If you make any assumptions, write them down explicitly. Show the participation cardinalities of all relationships, and mark primary keys. Your database should capture the following information. ITEMS: Each item has a name, description, pictures, a minimum price, an increment, and an expiry date associated with it. For each item, the current maximum bid is also stored explicitly. Items are owned by a specic owner. OWNERS: Owners have information such as name, phone number, address, preferred payment method. In addition, owners have ratings which are determined by the comments made about them. Only owners can introduce new items to be sold at the store and also accept a specic bid. BUYERS: Buyers have similar information as owners. However, only buyers can place bids on items. A person can be an owner, a buyer or both. ACTIVE BIDS: Each bid is made at a specic time, for a specic item and for a specic amount. Each bid is made by a single buyer. TRANSACTIONS: Each transaction involves a buyer, an owner, a date and an amount. This means that an owner accepted a bid by a buyer for the given amount. COMMENTS: Both owners and buyers can comment on the transaction they have conducted. Owners can rate buyers and vice versa. For each comment, there is commentor (person commenting), commentee (the person being commented on), a rating (one of ve set values poor to excellent), and additional notes. In addition, owners can accept any bid for an item they are selling. At this time, both the item and all the bids for the item are removed from the database (this has to supported as application logic separately) and a transaction tuple is generated.

17

Answer 12 Here is an example E-R diagram (Figure 13). I have split the comments into two, owner comments (OCOMMENTS) shown below, and buyer comments (BCOMMENTS) which is identical to OCOMMENTS. In owner comments, an owner is commenting on the buyer. Each comment is for a transaction (XACT). Note that, given a transaction, you can nd out who the owner and the buyer was. You can make comments a relationship on people (owners or buyers) instead of my solution. Note that, even though only owners accept bids, there is no need to represent that as a relationship. You will probably enforce that in some other way.

time name picture description increment Min_price Max_bid Exp_date

BIDS
1 place N
name

id amount address phone ratings p_p_m

ITEMS
1

id

BUYERS
N

ownedby

involve N

OWNERS
id p_p_m name phone address ratings id

XACTS

for

OCOMMENTS
id amount date

notes rating

Figure 13: ER diagram

18

Question 13 Draw an entity-relationship diagram for the following database. Draw entities and relationships carefully. For each relationship, write the min and max participation cardinalities for all entities it combines. For each entity, draw at least 4 representative attributes and mark the primary key carefully. Since everything about this model is not specied in detail, you need to decide what is reasonable for this application. If you make any assumptions about your model, write them down as short notes. In this database, you will represent the following information about a university: The university has a number of schools and dierent departments in each school. It also has a number of faculty and centers for research. Faculty members have names, ssn, major interests, oce location and number. school has a Dean, which is a faculty member. A department has a chair, which is a faculty member. Each faculty is in a single department, but they may have joint appointments with multiple departments and research centers. Research centers have directors, which are also faculty members. Faculty and research centers receive grants. Each grant has a starting date, amount, granting institution and a program director. There may be multiple faculty and/or research centers aliated with a grant. DESIGN NOTES: When designing a database, you should try to keep in mind the following conicting rules: A simple database is easier to implement. This usually means you should try to limit the number of entities and relationships as much as possible as long as you can capture everything that you need in the data model. Each entity should have a specic logical meaning/purpose. While you would be simplifying the data model by combining many similar entities to a single entity, you will need to handle exceptions in application code later on. You should try to nd the appropriate balance between these two factors in your design.

19

Answer 13 Figure 14 is an example solution to this problem. One thing to note is that grants are received by faculty and/or research centers. Each grant may have no center associated with it. Also, there are cases grants are given to a research center but there is usually a faculty associated with the grant as the primary investigator.

MainOffice Name Phone

YearFounded Name

MainOffice Phone

Mission

School
Name SSN

interests

OfficePhone OfficeRoom

Rcenter
affiliation2 N 1 directs N

1 1 N affiliation N in N 1 chairs 1 1

N 1

Dean-of

Faculty
N receive2 N N

receive

Department

Grants

Name History

ID MainOffice Facilities Institution StartDate

Amount ProgramDir.

Figure 14: ER diagram

20

Question 14 You are given an entity-relationship diagram shown in Figure 15 and 16. Convert this to an equivalent and succinct relational schema (i.e. set of relations). Underline the primary key of each relation. List all foreign keys. Example. R(A, B), S(D,E, F), Foreign keys: S.F references R.A.

Service
N N
hours

Location
N

provide
N

Located-at Take-place
1 N

Organization
N

sponsor

Event
N

affiliated-with
N 1

Of-type

Contact People

Category

N Sub-category N

Figure 15: Relationships

21

mission Name Date-founded Phone-number Name

Event

date

eid Age-group

Organization
description Name Login-name Phone-number Room-number

times State-date

End-date

Login-password

Location

Parking-info

Contact People

Name

address

directions city street state

zip

Service

Category

Name description

eligibility Age-group Name description

Figure 16: Attributes for the entities

Answer 14 Relational schema: Organization(Name, DateFounded, Mission, Location) Organization(Location) Location(Name) OrganizationPhone (OrgName, PhoneNumber) OrganizationPhone (OrgName) Organization(Name) Event(EID, Name, Description, StartDate, EndDate, Sponsor, Location) Event(Sponsor) Organization(Name) Event(Location) Location(Name) EventAges(EID, AgeGroup) EventAges(EID) Event(EID) EventTimes(EID, Time) EventTimes(EID) Event(EID) ContactPeople(OrgName, PersonName, LoginName, LoginPassword, PhoneNumber, RoomNumber) ContactPeople(OrgName) Organization(Name) Location(Name, Directions, City, Street, State, Zip, ParkingInfo) Service(Name, Description, Eligibility)

22

ServiceAges(Sname, AgeGroup) ServiceAges(Sname) Service(Name) Category(Name, Description) ProvideService(OrgName, ServiceName, Hours) ProvideService(OrgName) Organization(Name) ProvideService(ServiceName) Service(Name) EventCategory(Event, Category) EventCategory(Event) Event(EID) EventCategory(Category) Category(Name) SubCategory(SubCat, SupCat) SubCategory(SubCat) Category(Name) SubCategory(SupCat) Category(Name)

23

Question 15 You are given the below relational model. Artist( ArtistName, ArtistYear, Origin, ArtistTones, Biography ) Song( SongId, SongName, DateComposed ) Album( AlbumId, AlbumTitle, Duration, Rating, Review, ReleaseDate, AlbumTones, ArtistName, ArtistYear, LabelName ) Track( AlbumId, TrackId, Recommended, SongId ) LyricsBy( SongId, ArtistName, ArtistYear ) MusicBy(SongId, ArtistName, ArtistYear ) MajorArtist( ArtistName ArtistYear, LabelName ) Foreign keys: Album(ArtistName, ArtistYear) Artist(ArtistName, ArtistYear) Track(AlbumId) Album(AlbumId) Track(SongId) Song(SongId) LyricsBy(SongId) Song(SongId) MusicBy(SongId) Song(SongId) LyricsBy(ArtistName, ArtistYear) Artist(ArtistName, ArtistYear) MusicBy(ArtistName, ArtistYear) Artist(ArtistName, ArtistYear) MajorArtist(ArtistName, ArtistYear) Artist(ArtistName, ArtistYear) According to the above data model, answer the following questions. Answer yes or no, and give a short (one sentence) explanation. 1. Is it possible for the same artist to write both the lyrics and music of the same song? 2. Is it possible for more than one artist to write the lyrics of the same song? 3. Is it possible for two artists to have same name? 4. Is it possible for two albums to have the same name? 5. Is it possible for an album to have no tracks? Answer 15 The answer is below: 1. Is it possible for the same artist to write both the lyrics and music of the same song? Yes, there is no constraint between tuples in relations LyricsBy and MusicBy relations. 2. Is it possible for more than one artist to write the lyrics of the same song? Yes, it is possible to have two tuples in the LyricsBy relation with the same song id, but dierent artist information. 3. Is it possible for two artists to have same name? Yes, as long as they are from dierent ArtistYear. 4. Is it possible for two albums to have the same name? Yes, since AlbumId is the primary key of this relation, not the name of the album. 5. Is it possible for an album to have no tracks? Yes, it is possible that there are no tuples in the Track relation for an album.

24

Question 16 You are given the following entities. Draw an Entity-Relationship diagram and place these entities. Add to this diagram the relationships below. For each relationship, clearly mark the participation constraints on all sides and draw the associated attributes if there are any. Entities: Book [primary key: ISBN] Publisher [primary key: name] Company [primary key: name] BookStore [primary key: name, address] Relationships: Each company is aliated with specic publishers. Companies should have at least three aliated publishers and can have as many as possible. Each publisher can be aliated with zero or more companies. Each book is published by one and only one publisher. Each publisher can publish many books. A book may be a new edition of an existing book, but it does not have to be. Each book may or may not have new editions. Each edition has a number. Each bookstore may belong to a specic company. A bookstore may be independent, and it may not belong to any company in the database. A company may have many bookstores. Each bookstore carries books. A book can be carried by none or many bookstores and each bookstore can carry none or many books. Answer 16 The gure is given below.

Number

NewEdition Of Published By

N 1

N PUBLISHER

N BOOK N
Affiliated With

Carries

COMPANY

N N BOOKSTORE 1
BelongsTo

Figure 17: ER diagram

25

Question 17 You are given the entity relationship diagram shown in Figure 18: 1. Find the corresponding relational data model. Indicate foreign keys clearly. 2. Answer the following questions true or false with a short explanation: (a) Should each review be written by a news reviewer? (b) Should each movie have a remake? (c) Should each newsreviewer work for a specic newspaper?

editor Name webaddr Name address

NewsReviewer
N

Works-for

Newspaper

Is-by
id rating webaddr text

1 1

Remake-of
N new old

Review
1

Has-review

Movie

Is-by2
N Independent Reviewer

Name Year-made

officalsite

Name

webaddr

Figure 18: E-R diagram

Answer 17 The relational model is given below: NewsReviewer(Name, WebAddr, NewspaperName) Primary Key (Name), Foreign key NewspaperName references Newspaper(Name) Newspaper(Name, Editor, Address) Primary Key (Name) Review(Id, Rating, WebAddr, Text, IsByName, IsByName2, MovieName, MovieYearMade) Primary Key (Id), Foreign key IsByName references NewsReviewer(Name), Foreign key (MovieName, MovieYearMade) references Movie(Name, YearMade), Foreign Key IsByName2 references IndependentReviewer(Name) IndependentReviewer(Name, WebAddr) Primary Key (Name) Movie(Name, YearMade, OcialSite, RemakeName, RemakeYear) Primary Key (Name, YearMade), Foreign Key(RemakeName, RemakeYear) references Movie(Name, YearMade)

26

Question 18 Draw an Entity-Relationship diagram for the following database. Books have a title, ISBN number, and a price. Authors have a name and address. Publishing companies have a name and address. One or more authors write a book. Authors often write more than one book. One publishing company publishes each book. A publishing company can publish many books. Each author of a book is paid a fee for writing the book. When multiple authors write a book they do not necessarily all receive the same fee. The fees also vary between books. Answer 18 Sample answer:

ISBN name

title

price

address

Book
N

prints

Publisher

writes
fee

Author

name

address

Figure 19: E-R diagram

27

Question 19 A database is being constructed to keep track of the teams and games of a sports league. A team has a number of players, not all of whom participate in each game. It is desired to keep track of the players participating in each game for each team, the position(s) they played in the game, and the result of the game. Design an Entity Relationship Diagram for this database. State any assumptions you make. Choose your favorite sport (hockey, football, baseball, basketball, etc.). Answer 19 The gure is given below.

TeamName Team N

Play

N 2 Years
PartOf

GameId

Game

Result

Player

PlayIn

Position

Id

Name

Figure 20: ER diagram

28

Vous aimerez peut-être aussi