20
1 3 2 1 0 9 8 7 6 5 4 $10 $30 $50 Kaimuki Kokua Theater Kaimuki Kokua Theater For reservations call: (808) 332-4525 and ask for Cathy

13210987654 $10$30$50 Kaimuki Kokua Theater For reservations call: (808) 332-4525 and ask for Cathy

Embed Size (px)

Citation preview

Page 1: 13210987654 $10$30$50 Kaimuki Kokua Theater For reservations call: (808) 332-4525 and ask for Cathy

1 32 10987654

$10 $30 $50

Kaimuki Kokua Kaimuki Kokua TheaterTheater

For reservations call: (808) 332-4525 and ask for Cathy

Page 2: 13210987654 $10$30$50 Kaimuki Kokua Theater For reservations call: (808) 332-4525 and ask for Cathy

Reservation SystemReservation System

• The ticket agency for the Kaimuki Kokua The ticket agency for the Kaimuki Kokua Theater has a Web-based system that Theater has a Web-based system that allow users to perform the following allow users to perform the following queries:queries:– Display all seats in the theaterDisplay all seats in the theater– Display seats by priceDisplay seats by price– Display available seats, given a particular Display available seats, given a particular

priceprice– Display reserved seats, including customer Display reserved seats, including customer

namename– Given a seat, cancel a reservationGiven a seat, cancel a reservation

Page 3: 13210987654 $10$30$50 Kaimuki Kokua Theater For reservations call: (808) 332-4525 and ask for Cathy

Design of Reservation DBDesign of Reservation DB

• Customers (Customers (cusIDcusID, cusFName, , cusFName, cusLName, cusPhone)cusLName, cusPhone)

• Seats (Seats (seatIDseatID, seatReserved), seatReserved)• Prices (Prices (priceIDpriceID, priceValue), priceValue)

– Value of price is separated from the Value of price is separated from the Seats table,Seats table,so that when prices are changed, only so that when prices are changed, only Prices table Prices table needs to be modified.needs to be modified.

Page 4: 13210987654 $10$30$50 Kaimuki Kokua Theater For reservations call: (808) 332-4525 and ask for Cathy

TablesTables

Customers

cusIDcuslNamecusfNamecusPhone

Seats

seatIDpriceIDcusIDseatReserved

Prices

priceID|priceValue

1

MM

1

Page 5: 13210987654 $10$30$50 Kaimuki Kokua Theater For reservations call: (808) 332-4525 and ask for Cathy

Create DB Create DB • Create Reservation DB, using Access.Create Reservation DB, using Access.• Link table, using relationship window.Link table, using relationship window.• Populate tables with sample data.Populate tables with sample data.

Page 6: 13210987654 $10$30$50 Kaimuki Kokua Theater For reservations call: (808) 332-4525 and ask for Cathy

Sample DataSample DataCustomers

Prices

Seats

Page 7: 13210987654 $10$30$50 Kaimuki Kokua Theater For reservations call: (808) 332-4525 and ask for Cathy

SQL for “Show All SQL for “Show All Seats”Seats”

• SELECT Seats.seatNum, SELECT Seats.seatNum, Prices.priceValue, Prices.priceValue, Seats.seatReserved Seats.seatReserved FROM Seats, Prices FROM Seats, Prices WHERE Seats.priceID = WHERE Seats.priceID = Prices.priceIDPrices.priceIDORDER BY Seats.seatIDORDER BY Seats.seatID

Page 8: 13210987654 $10$30$50 Kaimuki Kokua Theater For reservations call: (808) 332-4525 and ask for Cathy

Your TurnYour Turn1.1. Show all $10 seatsShow all $10 seats

2.2. Show all available seatsShow all available seats

3.3. Show all $10 seats that are availableShow all $10 seats that are available

4.4. Show all $10 or $20 seats that are Show all $10 or $20 seats that are availableavailable

5.5. Show all seats that are reserved Show all seats that are reserved (including their seadNum, prices, (including their seadNum, prices, and customers)and customers)

6.6. Cancel reservation for seat No. 3Cancel reservation for seat No. 3

Page 9: 13210987654 $10$30$50 Kaimuki Kokua Theater For reservations call: (808) 332-4525 and ask for Cathy

Your TurnYour Turn

7.7. Add a new customer named Kaye Add a new customer named Kaye Kenton whose phone number is Kenton whose phone number is (808)592-5645.(808)592-5645.

8.8. Cancel a reservation for Carol Cancel a reservation for Carol Chang.Chang.

9.9. Remove the customer named Carol Remove the customer named Carol Chang.Chang.

Page 10: 13210987654 $10$30$50 Kaimuki Kokua Theater For reservations call: (808) 332-4525 and ask for Cathy

ASP to show all seatsASP to show all seats

• Seats.aspSeats.asp

Page 11: 13210987654 $10$30$50 Kaimuki Kokua Theater For reservations call: (808) 332-4525 and ask for Cathy

Result of ASP ProcessingResult of ASP Processing

• HTML Page HTML Page returned by returned by seats.aspseats.asp

Page 12: 13210987654 $10$30$50 Kaimuki Kokua Theater For reservations call: (808) 332-4525 and ask for Cathy

Answers to SQL Answers to SQL QuestionsQuestions

1.1. SELECT Seats.seatid, Prices.priceValueSELECT Seats.seatid, Prices.priceValueFROM Seats, PricesFROM Seats, PricesWHERE Seats.priceID=Prices.priceIDWHERE Seats.priceID=Prices.priceIDAND Prices.priceValue=10AND Prices.priceValue=10

2.2. SELECT Seats.seatNum, Prices.priceValueSELECT Seats.seatNum, Prices.priceValueFROM Seats, PricesFROM Seats, PricesWHERE Seats.priceID=Prices.priceIDWHERE Seats.priceID=Prices.priceIDAND Seats.seatReserved=falseAND Seats.seatReserved=false

3.3. SELECT Seats.seatNum, Prices.priceValueSELECT Seats.seatNum, Prices.priceValueFROM Seats, PricesFROM Seats, PricesWHERE Seats.priceID=Prices.priceIDWHERE Seats.priceID=Prices.priceIDAND Seats.seatReserved=falseAND Seats.seatReserved=falseAND Prices.priceValue=10AND Prices.priceValue=10

Page 13: 13210987654 $10$30$50 Kaimuki Kokua Theater For reservations call: (808) 332-4525 and ask for Cathy

Answers to SQL Answers to SQL QuestionsQuestions

4.4. SELECT Seats.seatNum, Prices.priceValueSELECT Seats.seatNum, Prices.priceValueFROM Seats, PricesFROM Seats, PricesWHERE Seats.priceID=Prices.priceIDWHERE Seats.priceID=Prices.priceIDAND Seats.seatReserved=falseAND Seats.seatReserved=falseAND (Prices.priceValue=10 AND (Prices.priceValue=10 OR Prices.priceValue=20)OR Prices.priceValue=20)

5.5. SELECT Seats.seatNum, Prices.priceValue, SELECT Seats.seatNum, Prices.priceValue, Customers.cusLNameCustomers.cusLNameFROM Seats, Prices, CustomersFROM Seats, Prices, CustomersWHERE Seats.priceID=Prices.priceIDWHERE Seats.priceID=Prices.priceIDAND Customers.cusID=Seats.seatIDAND Customers.cusID=Seats.seatIDAND Seats.seatReserved=trueAND Seats.seatReserved=true

6.6. UPDATE SeatsUPDATE SeatsSET seatReserved=false, cusID=NullSET seatReserved=false, cusID=NullWHERE seatID=3WHERE seatID=3

Page 14: 13210987654 $10$30$50 Kaimuki Kokua Theater For reservations call: (808) 332-4525 and ask for Cathy

Answers to SQL Answers to SQL QuestionsQuestions

7.7. INSERTINSERTINTO Customers(cusFname, cusLname, cusPhone)INTO Customers(cusFname, cusLname, cusPhone)VALUES (“Kaye”, “Kenton”, “(808)592-5645”);VALUES (“Kaye”, “Kenton”, “(808)592-5645”);

8.8. UPDATE SeatsUPDATE SeatsSET seatReserved = false, cusID = NULLSET seatReserved = false, cusID = NULLWHERE Seats.cusID =WHERE Seats.cusID = (SELECT Customers.cusID (SELECT Customers.cusID FROM Customers FROM Customers WHERE cusFname = 'Carol‘ WHERE cusFname = 'Carol‘ AND cusLName = 'Chang'); AND cusLName = 'Chang');

Page 15: 13210987654 $10$30$50 Kaimuki Kokua Theater For reservations call: (808) 332-4525 and ask for Cathy

Improved Reservation Improved Reservation SystemSystem

• Problems with Reservations DB Problems with Reservations DB version. 1version. 1– Usually, Usually, Customers ←→ Seats Customers ←→ Seats is a many-is a many-

to-many relationship.to-many relationship.– Version 1 does not allow for seat Version 1 does not allow for seat

reservations on different days.reservations on different days.

• How can we improve the DB design?How can we improve the DB design?

Page 16: 13210987654 $10$30$50 Kaimuki Kokua Theater For reservations call: (808) 332-4525 and ask for Cathy

Improved Reservation Improved Reservation SystemSystem

Customers

cusIDcuslNamecusfNamecusPhone

Seats

seatIDpriceIDcusIDseatReserved

Prices

priceID|priceValue

M

MM

1

Introduce a linking table between Customers and Seats tables.

Page 17: 13210987654 $10$30$50 Kaimuki Kokua Theater For reservations call: (808) 332-4525 and ask for Cathy

Improved Reservation Improved Reservation SystemSystem

Customers

cusIDcuslNamecusfNamecusPhone

Reserevations

cusIDseatIDdateID

Prices

priceID|priceValue

1 M

M

1

Seats

seatIDseatNumpriceIDcusIDseatReserved

1M

Dates

dateID|perfDate

M

1

Page 18: 13210987654 $10$30$50 Kaimuki Kokua Theater For reservations call: (808) 332-4525 and ask for Cathy

Query on Reservations Query on Reservations version 2version 2

1.1. Display seat number and prices of Display seat number and prices of all seats.all seats.

2.2. Display seat number and prices of Display seat number and prices of all unreserved seatsall unreserved seats

3.3. Display customers with reservations Display customers with reservations and their dates and seatsand their dates and seats

Page 19: 13210987654 $10$30$50 Kaimuki Kokua Theater For reservations call: (808) 332-4525 and ask for Cathy

SolutionsSolutions

1.1. SELECT seatNum, priceValueSELECT seatNum, priceValueFROM Seats, PricesFROM Seats, PricesWHERE Prices.priceID = WHERE Prices.priceID = Seats.priceIDSeats.priceID

2.2. SELECT seatNum, priceValueSELECT seatNum, priceValueFROM Seats, PricesFROM Seats, PricesWHERE Prices.priceID = WHERE Prices.priceID = Seats.priceIDSeats.priceIDAND seatReserved = false;AND seatReserved = false;

Page 20: 13210987654 $10$30$50 Kaimuki Kokua Theater For reservations call: (808) 332-4525 and ask for Cathy

SolutionsSolutions

3.3. SELECT Customers.cusFname, SELECT Customers.cusFname, Customers.cusLname, Customers.cusLname, Seats.seatNum, Dates.perfDate Seats.seatNum, Dates.perfDateFROM Customers, Reservations, Dates, FROM Customers, Reservations, Dates, SeatsSeatsWHERE Customers.cusID = WHERE Customers.cusID = Reservations.cusIDReservations.cusIDAND Dates.datID = Reservations.datIDAND Dates.datID = Reservations.datIDAND Seats.seatID = AND Seats.seatID = Reservations.seatIDReservations.seatIDAND Seats.seatReserved = True;AND Seats.seatReserved = True;