eranswers

Embed Size (px)

Citation preview

  • 8/6/2019 eranswers

    1/28

    Question 1 Find the relational tables that correspond to the E-R diagram in Figure 1. Use as few tables aspossible. For each relation, underline the primary key completely and list all foreign keys clearly on the side or byarrows.

    Customer

    Beneficiary

    Related-to

    father-of

    father

    children

    N

    1

    Name Address

    SSN

    Relationship

    Items-in-will

    Name Address

    N

    1

    Figure 1: E-R diagram

    Answer 1 Relational schema:

    Customer(SSN, Name, Address, FatherSSN )Foreign key FatherSSN refers to SSN of Customer

    Beneficiary( 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 Beneficiary

    Items should be a different relation since you cannot store multiple values for an attribute (i.e. sets) in relations.

    1

  • 8/6/2019 eranswers

    2/28

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

    BRANCH

    LOANCUSTOMER

    PAYMENTEMPLOYEE

    Loan-branch

    borrower

    Cust-banker Loan-payment

    ESSN

    Dependent-name

    Works_for

    Employment-length

    Start-date

    Phone#

    name

    SSN

    address

    name

    Branch-name

    Branch-city

    assets

    Loan-number

    amount

    Payment#

    Payment_date

    Payment_amount

    type

    N

    N

    N

    N

    N

    N

    1

    1

    1

    1

    manager

    worker

    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 ref-erences Employee(SSN)

    Loan(Loan Number, Amount, BorrowerSSN, Loan Branch)Primary Key(Loan Number), Foreign Key BorrowerSSN references Employee(SSN), Foreign Key Loan Branchreferences Branch(Branch Name)

    Payment(Loan Number, PaymentNo, Payment Date, Payment Amount)Primary Key (Loan Number, PaymentNo), Foreign Key Loan Number references Loan(Loan Number)

    2

  • 8/6/2019 eranswers

    3/28

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

    Employee

    Department

    Resource

    Works-for

    Owns

    ProjectDirects

    EID

    Supervises

    Classification

    Ename

    Title

    Dname

    Locations

    DID

    ResID Description

    Expiration Date PID

    N

    N

    N

    N

    N 1

    1

    1

    supervisee

    supervisor

    Figure 3: E-R diagram

    3

  • 8/6/2019 eranswers

    4/28

    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, Classification, 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 respectto all employees that they supervise.

    4

  • 8/6/2019 eranswers

    5/28

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

    Store Chain

    Product

    Belongs_to

    Sells

    StoreID StoreName

    Stock_qty

    ProductIDProduct_Name

    ChainName

    N1

    N

    N

    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 ref-

    erences Product(ProductId)

    5

  • 8/6/2019 eranswers

    6/28

    Question 5 Suppose you are constructing a database for a radio station. Your database is going to store the CDsyour station owns and also the program information about broadcasts of your station. You will store the followingpieces 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 different shows.

    Broadcasters usually have a number of shows they produce periodically.

    At each specific airing of a show, there is a play list which contains a number of songs from specific CDs in aparticular order.

    Draw an entity-relationship diagram for your database. You can use the E-R diagram from Question 1 as partof your database or introduce a modified version of it. Choose 2-4 attributes for each entity. Show all entities,relationships and attributes clearly. Clearly mark identifiers and the cardinalities of all relationships. If you makeany 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 attributesfor these entities.

    6

  • 8/6/2019 eranswers

    7/28

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

    BROADCASTERS

    AIRINGS

    SHOWS

    CDS

    SONGS

    produce

    contain

    have

    id

    name

    address

    salary nameformat

    order

    timedate

    N 1

    1

    N

    N

    N

    N

    Figure 5: E-R diagram

    7

  • 8/6/2019 eranswers

    8/28

    Question 6 You are asked to construct a database for managing the X-Files, i.e. criminal case descriptions and thepeople 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 identifier. If a specific attribute is a foreign key to another relation, write a

    short note indicating this. Use as few tables as possible.

    AGENTSX-FILES

    CONSPIRATORS

    Works-on

    Involved-in

    NEWSPAPERARTICLES

    FBI-ID

    Text

    Name

    FilenoPeopleInvolved CaseLocation

    CodeName Name

    Date

    N

    N

    N

    N

    FirstNameLastName

    ArticleNo

    Newspaper

    DescriptionStartDate

    Rank

    FirstNameLastName

    Figure 6: ER diagram

    Part 2. Add the following relationships to the entity relationship diagram in Part 1. Indicate the cardinalities clearlyfor 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.

    8

  • 8/6/2019 eranswers

    9/28

    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, XfileNo )

    Agent1 and Agent2 attributes in the X-FILES table are both foreign keys to the FBI-ID attribute of the AGENTStable.

    Fileno attribute in the XFILE-PeopleInvolved relation is a foreign key that refers to the Fileno attribute of theXFILE table.

    ConspiratorName attribute in the INVOLVED-IN table is a foreign key that refers to the CodeName attributeof the CONSPIRATORS table.

    XfileNo 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 everybodyhas a single father. Newspaper articles that do not refer to any X-Files may still exist in the database.

    AGENTS

    CONSPIRATORS

    X-FILES

    NEWSPAPERARTICLES

    Follow

    Father-of Subject-of

    N

    1N

    N

    N

    1Follows

    Followed-by

    Figure 7: E-R diagram

    9

  • 8/6/2019 eranswers

    10/28

    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. Ineach table, underline the primary identifier. If a specific attribute is a foreign key to another relation, write a shortnote indicating this. Use as few tables as possible.

    PEOPLE STORES

    CREDIT CARD CATALOG

    SSNFirstName

    LastName

    AddressID Location

    Name

    Number

    Name

    ExpirationDate

    CreditLimit

    NameDate_of_Pub

    Figure 8: E-R diagram

    10

  • 8/6/2019 eranswers

    11/28

    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 Peo-ple(SSN, LastName, Address), Foreign Key Number references CreditCard(Number)

    CATALOGCREDITCARD

    STORESPEOPLE

    hasCard

    N

    N

    sponsor

    N

    1

    sponsor

    1

    1

    Figure 9: E-R diagram

    11

  • 8/6/2019 eranswers

    12/28

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

    InsuranceCompany

    Person Carowns

    insures

    SSN

    name

    address

    premium

    nameaddress

    makeid

    N

    1

    N

    N

    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

  • 8/6/2019 eranswers

    13/28

    Question 9 You are given a preliminary data model for a library. It consists of the following entities:

    BOOKS correspond to different books with a unique ISBN number.

    PUBLISHERS correspond to different publishing houses, with given name and address.

    AUTHORS correspond to different 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 carefullyto 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 affiliated with a publisher at a given year. At any year, each author is affiliated 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.

    BOOK

    PUBLISHER

    AUTHOR

    BOOKCOPY

    WriteEdit

    N N

    Role

    Publishes

    N

    1

    CopyOf

    1

    NNewEdition

    1previous edition

    Nnext edition

    Figure 11: ER diagram

    13

  • 8/6/2019 eranswers

    14/28

    Question 10 You are given the following simple database of employees that work in specific departments. Eachdepartment has an inventory of items with specific quantity.

    EMPLOYEE(ssn, first-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 different id areconsidered different 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 different 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 briefly 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 primarykey 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 departmentand only one manager information can be stored in a single tuple.

    3. Can different departments have the same item-id in their inventory?

    Yes, it is possible to have two tuples with the same item-id, but different department numbers because theprimary 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

  • 8/6/2019 eranswers

    15/28

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

    STORES USERS

    ITEMS CATEGORIES

    Soldwith

    Prefer

    Belong_to

    Soldby

    Subcat

    Buy

    price

    color

    size

    name

    description

    ID

    name

    location

    name

    ID phone

    priority

    nameNN

    groupitem

    N1N

    N

    N

    N

    N

    N

    N

    super

    sub

    Figure 12: E-R diagram

    15

  • 8/6/2019 eranswers

    16/28

    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! Itis a design limitation.

    16

  • 8/6/2019 eranswers

    17/28

    Question 12 In this question, you are asked to create an entity-relationship diagram for an auction house. In thisdatabase, people register as buyers and/or owners, post items, and place bids on items. First decide on the primaryentities in your database and draw the major relationships between the entities. Then, add the necessary attributesfor entities and relationships either on your graph or list them separately. If you make any assumptions, write themdown 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 associatedwith it.

    For each item, the current maximum bid is also stored explicitly.

    Items are owned by a specific 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 specific 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 specific time, for a specific item and for a specific 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 bidby a buyer for the given amount.

    COMMENTS:

    Both owners and buyers can comment on the transaction they have conducted. Owners can rate buyers andvice versa.

    For each comment, there is commentor (person commenting), commentee (the person being commented on), arating (one of five 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 bidsfor the item are removed from the database (this has to supported as application logic separately) and a transactiontuple is generated.

    17

  • 8/6/2019 eranswers

    18/28

    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 ownercomments, an owner is commenting on the buyer. Each comment is for a transaction (XACT). Note that, given atransaction, you can find 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 willprobably enforce that in some other way.

    ITEMS

    OWNERS XACTS OCOMMENTS

    BIDS

    BUYERS

    place

    involveownedby

    for

    name

    picture

    description

    increment

    Min_price

    Max_bid

    Exp_date

    time

    id

    amount

    id

    name

    phone

    address

    ratings

    p_p_m

    id

    rating

    notes

    id

    phone

    address

    ratings

    p_p_m

    name

    id

    amount

    date

    N

    N

    N

    N

    N

    N

    1

    1

    1

    1

    Figure 13: ER diagram

    18

  • 8/6/2019 eranswers

    19/28

    Question 13 Draw an entity-relationship diagram for the following database. Draw entities and relationshipscarefully. For each relationship, write the min and max participation cardinalities for all entities it combines. Foreach entity, draw at least 4 representative attributes and mark the primary key carefully.

    Since everything about this model is not specified in detail, you need to decide what is reasonable for thisapplication. 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 different departments in each school. It also has a number offaculty and centers for research.

    Faculty members have names, ssn, major interests, office 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 andresearch 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 anda program director. There may be multiple faculty and/or research centers affiliated with a grant.

    DESIGN NOTES:

    When designing a database, you should try to keep in mind the following conflicting rules:

    A simple database is easier to implement. This usually means you should try to limit the number of entitiesand relationships as much as possible as long as you can capture everything that you need in the data model.

    Each entity should have a specific logical meaning/purpose. While you would be simplifying the data modelby combining many similar entities to a single entity, you will need to handle exceptions in application codelater on.

    You should try to find the appropriate balance between these two factors in your design.

    19

  • 8/6/2019 eranswers

    20/28

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

    School

    GrantsDepartment

    Rcenter

    FacultyDean-of

    affiliation

    in

    chairs

    affiliation2

    directs

    receive2

    receive

    Name

    MainOffice

    Phone

    YearFounded

    Name

    History

    MainOfficeFacilities

    SSN

    Name

    interests

    OfficeRoom

    OfficePhone

    Name

    MainOffice

    Phone

    Mission

    ID

    InstitutionStartDate

    ProgramDir.

    Amount

    1

    1

    1 1

    1

    1

    1

    N

    NN

    N

    N

    N

    N

    N

    N

    Figure 14: ER diagram

    20

  • 8/6/2019 eranswers

    21/28

    Question 14 You are given an entity-relationship diagram shown in Figure 15 and 16. Convert this to an equivalentand succinct relational schema (i.e. set of relations). Underline the primary key of each relation. List all foreignkeys.

    Example. R(A, B), S(D,E, F), Foreign keys: S.F references R.A.

    Service

    Organization

    Location

    Event

    CategoryContact People

    provide

    affiliated-with

    Located-at

    sponsor

    Take-place

    Of-type

    Sub-category

    hoursN

    N

    N

    N

    N

    N

    N

    N

    N

    1

    1

    1

    N

    Figure 15: Relationships

    21

  • 8/6/2019 eranswers

    22/28

    Contact People

    Location

    Service

    Organization

    Event

    Category

    NameDat e- founded Ph one- number

    mission

    Login-password

    Login-name

    Room-number

    Phone-number

    Name

    Name

    descriptionAge-group

    eligibility

    Name description

    Name

    directions

    address

    Parking-info

    city

    street state

    zip

    Name

    description

    Age-group

    eid

    date

    times

    State-date

    End-date

    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

  • 8/6/2019 eranswers

    23/28

    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

  • 8/6/2019 eranswers

    24/28

    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 different artistinformation.

    3. Is it possible for two artists to have same name?

    Yes, as long as they are from different 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

  • 8/6/2019 eranswers

    25/28

    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 allsides 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 affiliated with specific publishers. Companies should have at least three affiliated publishersand can have as many as possible. Each publisher can be affiliated 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 havenew editions. Each edition has a number.

    Each bookstore may belong to a specific company. A bookstore may be independent, and it may not belongto 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 cancarry none or many books.

    Answer 16 The figure is given below.

    BOOK

    PUBLISHER

    COMPANY

    BOOKSTORE

    AffiliatedWith

    N

    N

    PublishedBy N

    1

    NewEditionOf

    Number

    1 N

    BelongsTo

    N

    1

    Carries

    N

    N

    Figure 17: ER diagram

    25

  • 8/6/2019 eranswers

    26/28

    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 specific newspaper?

    NewsReviewer

    Movie

    Independent

    Reviewer

    Review

    NewspaperWorks-for

    Remake-of

    Has-review

    Is-by2

    Is-by

    Name webaddrName

    editor

    address

    id

    rating

    webaddr

    text

    Namewebaddr

    Name

    Year-made

    officalsite

    new old

    N

    N

    N

    N

    N

    1

    1

    1

    1

    1

    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, MovieYear-Made) references Movie(Name, YearMade), Foreign Key IsByName2 references IndependentReviewer(Name)

    IndependentReviewer(Name, WebAddr)Primary Key (Name)

    Movie(Name, YearMade, OfficialSite, RemakeName, RemakeYear)Primary Key (Name, YearMade), Foreign Key(RemakeName, RemakeYear) references Movie(Name, Year-Made)

    26

  • 8/6/2019 eranswers

    27/28

    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 authorswrite a book. Authors often write more than one book. One publishing company publishes each book. A publishingcompany can publish many books. Each author of a book is paid a fee for writing the book. When multiple authorswrite a book they do not necessarily all receive the same fee. The fees also vary between books.

    Answer 18 Sample answer:

    Author

    Book Publisherprints

    writes

    title

    ISBN

    price

    fee

    nameaddress

    nameaddress

    N1

    N

    N

    Figure 19: E-R diagram

    27

  • 8/6/2019 eranswers

    28/28

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

    Answer 19 The figure is given below.

    Team

    Player

    Game

    PlayN

    2GameId

    ResultPartOf

    N

    N

    Id Name

    PlayIn

    N

    N Position

    Years

    TeamName

    Figure 20: ER diagram