full set

17
CS304 Tutorial1 Full Set –E-R diagrams Abstract Tutorial 1, cs304– ER diagrams This tutorial consists of 4 questions of ER diagrams. Q1 is a small one so that students feel it easy to follow the specs. listed one by one. Q2 is a question used in previous course about a ”Motor Vehicle Branch”’s management system. It’s a small ER containing only 5 entities and 3 relationships. Students are able to do the ER diagram once in a whole. Q3 is a bigger design task, for this one, students need step by step create their ER diagrams so that no constraints in spec. will be missed. Q4 is a totally ”FreeStyle” design of a ”Movies4all” webservice in which basic elements are given and students need to come to their own idea of how these elements are organized together. They need to come to their own assumptions and comments for the ER diagram. Students should work in groups before answers are demonstrated. 1 Question1 Draw an ER diagram for the following application from the manufacturing in- dustry: 1. Each supplier has a unique name. 2. More than one supplier can be located in the same city. 3. Each part has a unique part number. 4. Each part has a colour. 5. A supplier can supply more than one part. 6. A part can be supplied by more than one supplier. 7. A supplier can supply a fixed quantity of each part. 1

Upload: imran

Post on 16-Nov-2014

718 views

Category:

Documents


2 download

DESCRIPTION

1234

TRANSCRIPT

CS304 Tutorial1 Full Set –E-R diagrams

Abstract

Tutorial 1, cs304– ER diagramsThis tutorial consists of 4 questions of ER diagrams. Q1 is a small

one so that students feel it easy to follow the specs. listed one by one. Q2is a question used in previous course about a ”Motor Vehicle Branch”’smanagement system. It’s a small ER containing only 5 entities and 3relationships. Students are able to do the ER diagram once in a whole.Q3 is a bigger design task, for this one, students need step by step createtheir ER diagrams so that no constraints in spec. will be missed. Q4 isa totally ”FreeStyle” design of a ”Movies4all” webservice in which basicelements are given and students need to come to their own idea of howthese elements are organized together. They need to come to their ownassumptions and comments for the ER diagram.

Students should work in groups before answers are demonstrated.

1 Question1

Draw an ER diagram for the following application from the manufacturing in-dustry:

1. Each supplier has a unique name.

2. More than one supplier can be located in the same city.

3. Each part has a unique part number.

4. Each part has a colour.

5. A supplier can supply more than one part.

6. A part can be supplied by more than one supplier.

7. A supplier can supply a fixed quantity of each part.

1

Figure 1: ER-diagram for supplier-part

2 A1

E-R diagram for Supplier-Part scenario.

3 Question2

The Motor Vehicle Branch administers driving tests and issues driver’s licenses.Any person who wants a driver’s license must first take a learner’s exam at anyMotor Vehicle Branch in the province. If he/she fails the exam, he can takethe exam again any time after a week of the failed exam date, at any branch.If he passes the exam, he is issued a license (type = learner’s) with a uniquelicense number. The person may take his driver’s exam at any branch any timebefore the learner’s license expiry date (which is usually set at six months afterthe license issue date). If he passes the exam, the branch issues him a driver’slicense.

Create a E-R diagram following these steps.

1. Find out the entities in the spec.

2. Find out the relationships among the entities.

3. Figure out attributes of the entities and (if any) of the relationships.

4. Figure out constraints between entities and relationships.

5. Check to see if you miss anything in spec.

2

Figure 2: Q2-ER diagram for motor-branch

4 A2

Step 1Entities:Driver: driver sin, driver name, driver birthdata, driver addr, driver city,

driver postalcode, driver phoneBranch: branch id, branch name, branch addr, branch phone, branch city,

branch postalcodeLicense: license no, license class, license expiryLearner license:Driver license:

Step 2 Relationships:owns(license, driver) takes exam(driver,branch):exam date, exam score, exam type

issues(license, branch): issue dataThe ”is a” relationshhip : Learner license, Driver license ”is a” license.

Step 3 constraints:1. a [driver] must <own> (at least one) [license].2. a [driver] must <take> at least one exam.3. a [license] must be <owned> by one and only one [driver].4. a [license] must be <issued> by one and only one [branch].

Step 4 Compose ER-diagram:Step 5 Check spec. again ........

5 Question3

We look at a larger design.

3

The Prescriptions-R-X chain of pharmacies has offered to give you a freelife-time supply of medicines if you design its database. Given the rising cost ofhealth care, you agree. Here is the information that you gather.

1. Patients are identified by SIN, and their names, addresses, and also ages.

2. Doctors are identified by an SIN, for each doctor, the name, specialty andyears of experience must be recorded.

3. Each pharmaceutical company is identified by name and has a phone num-ber.

4. For each drug, the trade name and formula must be recordered. Eachdrug is sold by a given pharmaceutical company, and the trade nameidentifies a drug uniquely from among the products of that company. If apharmaceutical company is deleted, you need not keep track of its productsany longer.

5. Each pharmacy has a name, address, and phone number.

6. Every patient has a primary physician. Every doctor has at least onepatient.

7. Each pharmacy sells several drugs and has a price for each. A drug couldbe sold at several pharmacies, and the price could vary from one pharmacyto another.

8. Doctors prescribe drugs for patients. A doctor could prescribe one or moredrugs for several patients, and a patient could obtain perscriptions fromseveral doctors. Each prescription has a date and a quantity associatedwith it. You can assume that if a doctor prescribes the same drug for thesame patient more than once, only the last such prescription needs to bestored.

9. Pharmaceutical companies have long-term contracts with pharmacies. Apharmaceutical company can contract with several pharmaceutical com-panies. For each contract, you have to store a start date, and end date,and the text of the contract.

10. Pharmacies appoint a supervisor for each contract. There must always asupervisor for each contract.

-End of the Spec.Tasks:

1. Draw a ER diagram that captures the above information. Identify andcontraints that are not captured by your ER-diagram.

2. How would your design change if each drug must be sold at a fixed priceby all the pharmacies?

3. How would your design change if the design requirements change as fol-lows: If a doctor prescribes the same drug for the same patient more thanonce, several such prescriptions may have to be stored separately.

4

Patient DoctorPrimary_Physician

Pharm_Co Make Drug Sell

Price

name

Prescribe

qty

date

Pharmacy

Contractstart_date

end_date

text supervisor

6 A3

Step 1 Identify entities.Patient: SIN,name,address,ageDoctor: phy sin, name, specialty, exp yearsPharm Company: name, phoneDrug: tradename, formulaPharmacy: name, address, phone

Step 2 Identify relationshipsPrimary Physican(Patient, Doctor)Prescribe(Patient, Doctor, Drug): date, qtySell(Pharmacy, Drug): PriceContract(Pharmacy, Pharm Co):start date, end date, text, supervisorMake(Drug, Pharm Co)

Step 3 Constraints1. a [patient] must and can only have one <Primary Physician >2. a [doctor] must be at least one [patient]’s <Primary Physician >3. a [drug] must be <made> by a [pharm co], and only have one maker.

Step 4 ER-DiagramStep 5 Check spec ............

Discuss Answers 2. put the attribute ”price” to ”make”.3. add a prescribe ID to relationship prescribe

5

7 Question4

Imagine that you are a consultant called into the office of a new Australian start-up called Movies4All. This company admires the success of the Internet MovieDatabase (IMDb) in collecting and publishing movie-related information via theweb and thinks that it can set up its own database to rival the IMDb. The pay-back to Movies4All, they hope, will be advertising revenue once thousands ofpeople-per-day start to visit their site looking for movie information/trivia/etc.

Putting aside your scepticism of this kind of business model, you ask themprecisely what content and functionality they want in their on-line database.They suggest that looking at the IMDb (http://www.imdb.com/) would be agood start.

If you press them further, they’ll tell you that Movies4All should maintainthe following kinds of information:

1. movies: title, cast, crew, story-line, genre, studio, year made/released

2. actors: biographical, photos, films they appeared in, ...

3. crew: occupation (director,cameraman,...), biographical, films, ...

4. studios: contact information, historical information (e.g. heads), ...

5. awards: given to movies or people who work in/on them

6. movie jobs: information about what people like ”gaffers” actually do

7. session times: for movies being screened in cinemas all over the world

All information in the system should be accessible (readable) to anyone onthe Internet. However, Movies4All staff are the only ones who are allowed toupdate the database. They also want to provide for registered users of thesystem, who can rate movies and post movie reviews. Registered users are alsoallowed to provide new information to the Movies4All staff, who will check itsvalidity and then incorporate it into the site.

Some ideas on the functionality that the system should provide:

1. Movies4All staff and registered users have a username and password forlogin authentication

2. Movies4All staff can add, update and (infrequently) delete any informationin the database

3. registered users can rate movies, post reviews, and post suggested changesto Movies4All staff

4. anyone can search for movies, actors, crew, ... via keyword

5. an advanced search facility allows search by individual aspects of movies/actors/crew/studios

6. every reference to a person/movie/studio is a hyperlink to a page givingthe details

Tasks: You need to analyse the challenge in this design and come up to anER-diagram.

6

8 A4

For big ER-diagram task. It’s good to do it in a ”divide-and-conquer” way.We come with entity to entity, relationship to relationship.Movies

Movie

MovieID

Story

Country

WebSite

Genre

RunTime

YearMade

Title

Figure 3: Movies

Write your comments just with the modeling.Comments:

1. the information here represents the core data about a movie

2. we use a numeric ID as a primary key, since Movies will be heavily referredto throughout the database

3. every movie must at least have a known title

4. information about classification, etc. (data that is related to a specificrelease of a movie) is pushed off into the MovieRelease entity

7

Movie Releases

Movie Released Movie Release

Country Rating

FinishingStarting

Figure 4: Movie Releases

Comments:

1. a Movie Release is a version of a movie that is issued for showing in someregion of the world

2. it may be changed in various ways from the original in the release (e.g. itmay have sub-titles added, or have scenes cut to fit in with a particularculture)

3. movies are rated to indicate which kind of audience thy are suitable for,and to indicate restrictions on who is allowed to view the movie

4. movie ratings are determined by an organisation (e.g. Censorship Board)within each country

5. no Box Office aspects of Movie Releases were included in this model (butif they had been, they would have been associated with Movie Relseases)

8

Movie People

Movie Person

StageName

Gender

BirthPlace

Birthday

Website

Biography Real Name

PersonID

Country

City

Figure 5: Movie People

Comments:

1. this Entity contains core personal information about people who are in-volved in the making of movies

2. we use a numeric ID for people, since they are heavily referenced throughthe rest of the database

3. the public is interested in biographical details of Movie People, and sothat is the primary information here

4. every person must at least have a know StageName

5. details about their involvement in particular movies and awards won ishandled via relationships with Movies and Awards entities

9

Photographs

Movie Person

Photo

Movie

StillFromPictureOf

CaptionData

PhotoID

Figure 6: Photographs

Comments:

1. each photograph may be associated with either a single individual or aspecific movie (but must be associated to at least one)

2. a photo of an actor in a given movie could be involved in both relationships

10

Movie People and Movies

Actor(ess)

Movie Role Movie

Move Job

Crew

Movie Person

IS_A

Appears In Works On

Name_In_MovieRole_ID

JobID

Title

Discription

Figure 7: Movie People and Movies

Comments:

1. the subclasses here are not used to indicate subclass-specific data; theyare used to ensure participation in the correct relationships

2. Movie People are assicated with particular movies in particular roles

3. Crew perform one or more jobs on a given movie; Actors play one or moreroles

4. it is possible for someone to be both Crew and Actor on a movie (e.g.acting and directing)

5. Directors and Producers would probably object to being called Crew; ifthis was an issue, we could introduce a new subclass called e.g. Produc-tionStaff

6. Movie People are not required to be associated with any Movie; this pre-sumably means that we don’t yet have such information to put in thedatabase

7. Roles for Actors and Jobs for Crew are analogous, and were designed tolook similar.

11

Awards

Award

Move Award Individual Award

Movie Movie Person

IS_A

AwardID

Organization Title

Category

Nominated For Id_Nominated ForisWinner

year

year

isWinner

Figure 8: awards

1. when an individual wins e.g. Best Actor Oscar, they win it for a perfor-mance in a particular movie

2. since Movie awards involve only a movie, the relationship is a differentkind to that for individuals, so we use subclasses to capture this

3. the Award entity holds generic information about the award

4. specific instances of the Award are only interesting in the context of whowas nominated and who won

5. an Award may have been won many times, or may have never beenawarded (or nominated)

6. there will be many nominations for an award in a given year, but only onewinner

7. an award may not be offered at all in a given year (no nominations andno winner)

12

Movie Companies

Movie Company

CompanyID

Name

Started

Country

Closed

Type

Movie Made By

Figure 9: Movie Companies

Comments:

1. this entity contains core data about companies involved in making movies

2. it is used for all different kinds of companies, from large Hollywood stu-dios (e.g. Paramount) down to smaller movie production companies (e.g.DreamWorks)

3. we use a numeric ID for similar reasons as above

4. the lifetime of a company is modelled via starting and closing dates

5. if a company moves to a different country, we would treat it as a clsoure,with re-opening in a new country

6. several companies may be involved in making a particular movie

7. movies may have no companies involved in their production (independent)

13

Cinemas

CinemaPhone

Name

CinemaID

City

Website

Province

#screens

Country

Street

Figure 10: Cinema

Comments:

1. in order to indicate screening times, we need to model cinemas

2. this entity captures the name/location/contact information that is mostlikely to be useful to users of the Movies4All site

3. cinemas can occur in multiplexes (multiple threatres/screens in a singlecomplex)

4. a multiplex must have at least some screens

14

Screenings

ScreeningMovie Releases Cinema

ShowTime

Figure 11: Screenings

Comments:

1. a Screening involves showing a release of a particular movie on a screenat a specified time or a specified date

2. obviously maintenance of such information on a world-wide scale wouldbe extremely tedious, but, fortunately, all we need to do is model it

15

Users(staff and Members)

User

Staff Member

IS_A

User_ID

ShowName

Name

Location

username

Password

Email

address PhoneVisit_times score

Figure 12: Users

Comments:

1. there are two kinds of users who can login to the Movies4All web site:Movies4All staff and members (registered users) of the site

2. we need to maintain basic contact data plus authentication data for all ofthese users

3. every user must have a unique username, and must have a password andan email address

4. for staff, we need additional contact information; we assume that otheremployment-related data for staff is held on a separate HR system

5. for members, we record various preferences, which will allow us to cus-tomise their viewing of the web site

6. preferences could be generalised via a (Property,Value) table, but we stickto a collection of predefined preference classes here

16

News and User Feedback

News

Movie

Movie Person

MovieRef

PersonRef

Posted By Staff

Title

NewsID

URL

CommentsPosted

Member MovieFeed-back

ItemID Title

Posted1 Comments

GivenBy Rate

Rating

Comments

Figure 13: News and User feedback

Comments:

1. staff members can post news items that refer to new stories posted onmainstream news web sites

2. these news items contain some brief local commentary (from a Movies4Allstaff member), a link to the original news story, and references to thepeople and movies being referred to in the news story

3. we also need to record when the staff member posted a news item

4. members can send information to the Movies4All staff; we need to recordwhen they sent it, and what it’s about (similar to a piece of internal email)

5. members can also provide feedback on movies in the form of either a one-to-five-star rating, or some text commentary (max 200 chars)

6. members can also assess the credibility (on a scale of 1-5) of other mem-bers, so that the site can implement expert reviewiers

7. titles may not be empty, and should be relatively brief (less than 50 chars)

8. the commentary in news items should be less than 200 characters (toprevent staff from getting carried away)

9. there is no limit on the length of a piece of user feedback, but it mustcontain some text

9 Acknowledgement

Credits are given to instructors of the equi. lectures at Uni. of New South Waleswhere credits due.

17