database examples. exercise a company database needs to store information about employees...

28
Database Examples

Upload: annice-robertson

Post on 14-Dec-2015

384 views

Category:

Documents


9 download

TRANSCRIPT

Page 1: Database Examples. Exercise A company database needs to store information about employees (identified by ssn, with salary and phone as attributes), departments

Database

Examples

Page 2: Database Examples. Exercise A company database needs to store information about employees (identified by ssn, with salary and phone as attributes), departments

Exercise

A company database needs to store information about employees (identified by ssn, with salary and phone as attributes), departments (identified by dno, with dname and budget as attributes), and children of employees (with name and age as attributes). Employees work in departments; each department is managed by an employee; a child must be identified uniquely by name when the parent (who is an employee; assume that only one parent works for the company) is known.

Draw an ER diagram that captures this information.

Page 3: Database Examples. Exercise A company database needs to store information about employees (identified by ssn, with salary and phone as attributes), departments

Academic Teaching Database

Design an E-R schema for a database to store info about professors, courses and course sections indicating the following:

The name and employee ID number of each professor The salary and email address(es) for each professor How long each professor has been at the university The course sections each professor teaches The name, number and topic for each course offered The section and room number for each course section Each course section must have only one professor Each course can have multiple sections

Page 4: Database Examples. Exercise A company database needs to store information about employees (identified by ssn, with salary and phone as attributes), departments

Case Study (Pine Valley Furniture Company )

1. The company sells a number of different furniture products.

These products are grouped into several product lines. The identifier for a product is Product_ID, while the

identifier for a product line is Product_Line_ID. Referring to the customer invoice, we identify the following

additional attributes for product: Product_Description, Product_Finish, and Unit_Price.

Another attribute fro product line is Product_Line_Name. A product line may group any number of products, but

must group at least one product. Each product must belong to exactly one product line.

Page 5: Database Examples. Exercise A company database needs to store information about employees (identified by ssn, with salary and phone as attributes), departments

Case Study

2. Customers submit orders for products The identifier fro an order is Order-ID, and another attribute is Order_Date.

A customer may submit any number of orders, but need not submit any orders.

Each order is submitted by exactly one customer. The identifier for a customer is Customer_ID. Other attributes include Customer_Name and

Customer_Address.

Page 6: Database Examples. Exercise A company database needs to store information about employees (identified by ssn, with salary and phone as attributes), departments

Case Study

3. A given customer order must request at least one product.

Any product sold by Pine Valley Furniture may not be requested on any order, or may be requested on one or more orders.

An attribute associated with each order and product is Quantity, which is the number of units requested.

Page 7: Database Examples. Exercise A company database needs to store information about employees (identified by ssn, with salary and phone as attributes), departments

Case Study

4. Pine Valley Furniture has established sales territories for its customers.

Each customer does business in one or more of these sales territories.

The identifier for a sales territory is Territory_ID.

A sales territory may have any number of customers, or may not have any customers doing business.

Page 8: Database Examples. Exercise A company database needs to store information about employees (identified by ssn, with salary and phone as attributes), departments

Case Study

5. Pine Valley Furniture Company has several salespersons. The identifier for a salesperson is Salesperson_ID.

Other attributes include Salesperson_Name, Salesperson_Telephone, and Salesperson_Fax.

A salesperson serves exactly one sales territory.

Each sales territory is served by one or more salespersons.

Page 9: Database Examples. Exercise A company database needs to store information about employees (identified by ssn, with salary and phone as attributes), departments

Case Study

6. Each product is assembled from one or more raw materials.

The identifier for the raw material entity is Material_ID.

Other attributes include Unit_of_Measure and Unit_Price.

Each raw material may be assembled into one or more products.

Page 10: Database Examples. Exercise A company database needs to store information about employees (identified by ssn, with salary and phone as attributes), departments

Case Study

7. Raw materials are supplied by vendors. The identifier for a vendor is Vendor_ID. Other attributes include Vendor_Name and

Vendor_Address. Each raw material can be supplied by one or

more vendors. A vendor may supply any numver of raw

materials, or may not supply any raw materials to Pine Valley Furniture.

An attribute of the relationship between vendor and raw material is Unit_Price

Page 11: Database Examples. Exercise A company database needs to store information about employees (identified by ssn, with salary and phone as attributes), departments

Case Study

8. Pine Valley Furniture has established a number of work centers.

The identifier for a work center is Work_Center_ID.

Another attribute is Location. Each product is produced in one or more work centers.

A work center may be used to produce any number of products, or may not be used to produce any products.

Page 12: Database Examples. Exercise A company database needs to store information about employees (identified by ssn, with salary and phone as attributes), departments

Case Study

9. The company has over 100 employees. The identifier for employee is Employee_ID. Other attributes are Employee_Name,

EmployeeAddress, and Sill. An employee may have more than one skill.

And Each skill can be mastered by many employees or none.

Page 13: Database Examples. Exercise A company database needs to store information about employees (identified by ssn, with salary and phone as attributes), departments

Case Study

10: Each employee works in one or more work centers.

A work center must have at least one employee working in that center, but may have any number of employees.

Page 14: Database Examples. Exercise A company database needs to store information about employees (identified by ssn, with salary and phone as attributes), departments

Case Study

11. Each employee has exactly one supervisor.

An employee who is a supervisor may supervise any number of employees, but not all employees are supervisors.

Page 15: Database Examples. Exercise A company database needs to store information about employees (identified by ssn, with salary and phone as attributes), departments
Page 16: Database Examples. Exercise A company database needs to store information about employees (identified by ssn, with salary and phone as attributes), departments

16

Case Study

Design a DB consistent with the following facts. Trains are either local trains or express trains, but

never both. A train has a unique number and an engineer. Stations are either express stops or local stops, but

never both. A station has a unique name and an address. All local trains stop at all stations. Express trains stop only at express stations. For each train and each station the train stops at, there

is a time.

Page 17: Database Examples. Exercise A company database needs to store information about employees (identified by ssn, with salary and phone as attributes), departments

ER Case StudyER Case Study

Each bank has a unique name.

Each branch has a number, name, address (number, street, city), and set of phones.

Customer includes their name, set of address (P.O. Box, city, zip code, country), set of phones, and social security number.

Accounts have numbers, types (e.g. saving, checking) and balance. Other branches might use the same designation for accounts. So to name an account uniquely, we need to give both the branch number to which this account belongs to and the account number.

Not all bank customers must own accounts and a customer may have at most 5 accounts in the bank.

An account must have only one customer.

A customer may have many accounts in different branches. 

Banks Database

Page 18: Database Examples. Exercise A company database needs to store information about employees (identified by ssn, with salary and phone as attributes), departments

Data Modeling Case Study

The following is description by a pharmacy owner: "Jack Smith catches a cold and what he suspects is a flu virus. He makes an appointment with his family doctor who confirm his diagnosis. The doctor prescribes an antibiotic and nasal decongestant tablets. Jack leaves the doctor's office and drives to his local drug store. The pharmacist packages the medication and types the labels for pill bottles. The label includes information about customer, the doctor who prescribe the drug, the drug (e.g., Penicillin), when to take it, and how often, the content of the pill (250 mg), the number of refills, expiration date, and the date of purchase."

Please develop a data model for the entities and relationships within the context of pharmacy. 18

Page 19: Database Examples. Exercise A company database needs to store information about employees (identified by ssn, with salary and phone as attributes), departments

Library Case Study

When a library first receives a book from a publisher it is sent, together with the accompanying delivery note, to the library desk. Here the delivery note is checked against a file of books ordered.

If no order can be found to match the note, a letter of enquiry is sent to the publishers. If a matching order is found, a catalogue note is prepared from the details on the validated delivery note.

The catalogue note, together with the book, is sent to the registration department. The validated delivery note is sent to the accounts department where it is stored.

On receipt of an invoice from the publisher, the accounts department checks its store of delivery notes. If the corresponding delivery note is found then an instruction to pay the publishers is made, and subsequently a cheque is sent. If no corresponding delivery note is found, the invoice is stored in a pending file. 

Page 20: Database Examples. Exercise A company database needs to store information about employees (identified by ssn, with salary and phone as attributes), departments

A Case Study Conference centre booking system

A conference centre takes bookings from clients who wish to hold courses or conferences at the centre. When clients make bookings they specify how many people are included in the booking, and of these, how many will be resident during the booking, and how many will require catered or non-catered accommodation at the centre.The centre contains a number of facilities which may be required by clients making bookings as follows:A. There are 400 bedrooms for clients who will be resident during the Course or

conference.B. A maximum of 250 catered people can be handled at any one time.C. Six main lecture theatres providing seating for 200 people.D. Twenty seminar rooms each able to accommodate 25 people.E. Video conference facilities. The video conference facilities consist of four separate

video conference networks. Each video conference network has a large screen based in one of the main lecture theatres, along with 3 satellite screens each of which is based in one of the seminar rooms.

Draw an entity relationship diagram for the case, stating any assumptions you deem necessary.

Page 21: Database Examples. Exercise A company database needs to store information about employees (identified by ssn, with salary and phone as attributes), departments

Shipping company example The London and Ireland Shipping Company PLC (LISC) was

founded in 1852 and owns a fleet of cargo ships. The company had historically run passenger liners, but recent policy decisions involved the sale of all passenger-carrying vessels. The company currently has 14 vessels, including one oil tanker and one tugboat operating out of Liverpool. Most of the vessels are registered in Liberia for tax reasons.

Each ship has one or more holds divided into spaces. The holds are defined by steel bulkheads and the spaces are defined by shelf racks or other physical dividers. Sister ships, built by the same shipbuilders and to the same designs have similar names, such as Pride of Ireland, Queen of Ireland, Song of Ireland and Warrior of Ireland. Sister ships also have identical cargo storage facilities.

LISC issues contracts to agents for one or more manifests (lists of cargo items to be shipped). LISC's charges for cargo carried are based on the number of spaces the cargo requires for storage. The types of cargo typically carried by LISC include grain, coal and ores (carried only in ships equipped with bulk cargo holds). They also transport sacked grain, heavy cases, containers (which may be carried on deck), pallets and so on.

Page 22: Database Examples. Exercise A company database needs to store information about employees (identified by ssn, with salary and phone as attributes), departments

Shipping company example Cargo items may take up less than one space in a hold, or one or

more spaces, depending on the size of the item. A space may therefore contain several small cargo items.

The ships owned by LISC are kept as busy and as full as possible, in order to maximise the profits that each vessel makes and minimise running & operating costs. LISC's ships ply most of the seas of the world, but tend to operate mainly in the Mediterranean, the North and Mid Atlantic and the Indian Ocean. Different ships require different crew complements.

LISC intends to create a computer based information system that will be able to perform the following tasks:

• record the voyages of each ship with the start and end ports. • record the cargo held by a ship on each voyage • keep records of their employees and the ships they are assigned

to • producing invoices for agents and customers • keep a record of customers' payments on invoices • analyse the efficiency of use of cargo space and of percentage

wasted cargo space for ships voyages

Page 23: Database Examples. Exercise A company database needs to store information about employees (identified by ssn, with salary and phone as attributes), departments

ER Case StudyER Case Study

Television Series Database

A Television network wishes to create a database to keep track of its TV series. A television series has one or more episode. Television series identified by name and season number, and includes their production company name and Num_of_Episodes ( i.e. total number of episodes in a specific season of a series ).

Episode of a specific season of a series is identified by episode number and has a title and a length. No episode can exist without a corresponding television series. Also each episode has only one writer. A writer is identified by name, and also has birth date and a literary agency that represents him or her.

An actor appears as a performer in a television series or a guest star on an episode. An actor is identified by name and also has a nationality and birth date. An actor plays a particular character in a television series or episode.

Page 24: Database Examples. Exercise A company database needs to store information about employees (identified by ssn, with salary and phone as attributes), departments

University DB Case Study

Maintain the following information about undergrad students: Name, address, student number, date of birth,

year of study, degree program (BA, BSc, BCS), concentration (Major, Honours, etc) and department of concentration.

Note: An address is composed of a street, city, province and postal code; the student number is unique for each student

Page 25: Database Examples. Exercise A company database needs to store information about employees (identified by ssn, with salary and phone as attributes), departments

University Case Study (cont’d)

Maintain information about departments Name, code (CS, Phy), office phone, and faculty

members

Maintain information about courses: Course number (3753), title, description,

prerequisites.

Maintain information about course sections: Section (A, B, C), term (X1), slot #, instructor

Page 26: Database Examples. Exercise A company database needs to store information about employees (identified by ssn, with salary and phone as attributes), departments

University Case Study (cont’d)

Maintain information about faculty: Name, rank, employee number, salary, office

number, phone number and email address. Note: employee number is unique

Maintain a program of study for the current year for each student: i.e. courses that each student is enrolled in

Page 27: Database Examples. Exercise A company database needs to store information about employees (identified by ssn, with salary and phone as attributes), departments

Film Club Case Study:

Film Club UK is a company that owns or leases a number of small cinemas in the UK. They have commissioned a database designer to design a database solution to enable them to maintain details about their cinemas and the films that they show. Note that it is possible to have two cinemas in the same location with the same name (there used to be two Odeons in Newcastle). It is also possible to have different films with the same title (for example, different versions of a Shakespeare play).

Films are scheduled for one or more showings at a cinema within a ‘season’. Season details are to be notified in advance of the dates and times of showings, takings, etc. to be notified later.

Any one film may have more than one season at any one cinema (for example, a cinema showing ‘The Snowman’ each Christmas). At present, all cinemas are single-screen.

Page 28: Database Examples. Exercise A company database needs to store information about employees (identified by ssn, with salary and phone as attributes), departments

Classroom Design ExerciseImagine we are creating a database for a dorm, which

includes a cooperative kitchen. We want to record certain information about each

resident. What? Not all residents belong to the kitchen coop. Those

that do interact in various ways:1. They take turns at various jobs: preparer, cleanup, buyer

(for supplies). No one should have two jobs on one day.2. They may or may not be vegetarian. Each meal must

have at least one vegetarian entreé.3. They pay fees to the coop.

For each meal, there is a menu. Each menu item requires certain ingredients, which must be on hand.