I've made a few changes based on my initial observations (see above) and this is what I have now (also see attached image):
Reservations
* Reservation Number (pk)
* Date Reservation Made
* Tax Code (fk)
ReservationTickets (linking table)
* Reservation Number (fk, cpk)
* Ticket ID (fk, cpk)
* Showtime (fk, cpk)
* Quantity
Shows
* Showtime (pk)
* isSoldOut
* isCancelled
Tickets
* Ticket ID (pk)
* Ticket Class
* Ticket Description
TicketPrices
* Ticket ID (fk, cpk)
* Valid From Date (cpk)
* Price
* Currency Code (fk)
TaxCodes
* Tax Code (pk)
* Description
SalesTaxRates
* Valid From Date (cpk)
* Tax Rate (cpk)
* Tax Code (fk)
Currencies (validation table)
* ISO Currency Code (pk)
Wondering how hard it would be to get the data I need from this model, I wrote a query to return Reservations with the total number of tickets, total cost, and total amount of tax paid:
Code:
SELECT ReservationNumber,
sum(Quantity) AS NumTickets,
sum((Price + Tax) * Quantity) AS Total,
sum(Tax * Quantity) AS TaxPaid
FROM (
SELECT r.ReservationNumber,
rt.Quantity,
tp.Price,
round(tp.Price * (str.TaxRate/100.0), 2) AS Tax
FROM Reservations r
JOIN ReservationTickets rt ON r.ReservationNumber = rt.ReservationNumber
JOIN Tickets t ON rt.TicketID = t.id
JOIN TicketPrices tp ON t.id = tp.TicketID
JOIN TaxCodes tc ON r.TaxCode = tc.TaxCode
JOIN SalesTaxRates str ON tc.TaxCode = str.TaxCode
) t
GROUP BY ReservationNumber
Which gives me something like this:
Code:
ReservationNumber NumTickets Total TaxPaid
1 3 95.02 6.22
2 4 255.96 16.76
3 5 221.07 14.47
Any feedback on this data model?
Thanks,
Nathan