Presentation is loading. Please wait.

Presentation is loading. Please wait.

Database design by Sarah Huynh.

Similar presentations


Presentation on theme: "Database design by Sarah Huynh."— Presentation transcript:

1 Database design by Sarah Huynh

2 Entity-Relationship Diagram

3 Venue Venue_Name Venue_Suburb Venue_State Race Race_ID Race_Time Race_Regatta* Race_Date Race_Distance Race_Type Race_Division Entry Race_ID* Crew_BowName* Crew Crew_BowName Crew_ClubName* Crew_BoatCategory Club Club_Name Club_Location Results Results_BowName* Results_RaceID* Results_Rank Results_TotalRaceTime Booking Venue_Name* Regatta_Name* Regatta Regatta_Name Regatta_Date Regatta_Type

4 One to Many Relationship Race Race_ID Race_Time Race_Regatta* Race_Date Race_Distance Race_Type Race_Division Regatta Regatta_Name Regatta_Date Regatta_Type A Regatta can have MANY Races but a Race can only belong to ONE Regatta.

5 Many to Many Relationship Race Race_ID Race_Time Race_Regatta* Race_Date Race_Distance Race_Type Race_Division Entry Race_ID* Crew_BowName* Crew Crew_BowName Crew_ClubName* Crew_Category A Race can have MANY Crews. A Crew can be in MANY Races. HOWEVER A race can have MANY entries. A Crew can have MANY Entries. An entry can only belong to ONE race. A Entry can only belong to ONE Crew.

6 Simple Query of a Single Table Display the ‘Club’ table SELECT * FROM Club; SELECT * FROM Club; Club_NameClub_LocationKingsParramatta ShoreNorthbridge St Ignatius Lane Cove Sydney Boys Moore Park QueenwoodMosman Tara School North Parramatta PLC Sydney Croydon Sydney Girls Moore Park South Grafton RC South Grafton Grafton RC Grafton Lower Clarance RC Lower Clarance Balmain RC Balmain UNSWGladesville Sydney Uni Linley Point UTSHaberfield Display all clubs called ‘UTS’ SELECT * FROM Club WHERE Club_Name = ‘UTS’; Club_NameClub_LocationUTSHaberfield

7 Natural join Display the name and venue name of regattas which occur in Penrith. SELECT Regatta_Name, Venue_Name FROM Venue NATURAL JOIN Booking WHERE Venue_Suburb = ‘Penrith’; Regatta_NameVenue_Name Loreto Normanhurst SIRC

8 Cross product Display the regatta name and venue name of regattas that occur in Penrith. SELECT Regatta_Name, Venue.Venue_Name FROM Venue, Booking WHERE Venue_Suburb = ‘Penrith’ and Venue.Venue_Name = Booking.Venue_Name; Regatta_NameVenue_Name Loreto Normanhurst SIRC

9 Group By Show the different number of boat categories entered into competition. SELECT Crew_BoatCategory, Count(*) FROM Crew GROUP BY Crew_BoatCategory; Crew_BoatCategoryCount Coxed Pair 4 Coxless Double 5 Coxed Quad Scull 6 Coxed Eight 6 Single Scull 11 Coxed Four 3

10 SubQuery Display the Race Id’s of races with results. SELECT DISTINCT Race_ID FROM Race NATURAL JOIN Results WHERE Race_ID IN (SELECT Race_ID FROM Results); Race_ID

11 Self join Show all Venues in the same State as the Venue ‘Clarence River’. Select TableVenuesA.Venue_Name, TableVenueA.Venue_State FROM Venue TableVenueA, Venue Table VenueB WHERE TableVenueA.Venue_State = TableVenueB.Venue_State AND TableVenueB.Venue_Name = ‘Clarence River’ AND TableVenueA.Venue_Name <> ‘Clarence River’; venue_name venue_namevenue_state SIRCNSW Iron Cove NSW Hen and Chicken NSW (3 rows)

12 CHECK Statement Checks that the user inserts correct data for ‘State’ value in the Venue table. Checks that the user inserts correct data for ‘State’ value in the Venue table. CONSTRAINT Venue_Venue_State CHECK ((Venue_State = 'NSW') OR (Venue_State = 'VIC') OR (Venue_State = 'QLD') OR (Venue_State = 'SA') OR (Venue_State = 'TAS') OR (Venue_State = 'WA') OR (Venue_State = 'NT'))); CONSTRAINT Venue_Venue_State CHECK ((Venue_State = 'NSW') OR (Venue_State = 'VIC') OR (Venue_State = 'QLD') OR (Venue_State = 'SA') OR (Venue_State = 'TAS') OR (Venue_State = 'WA') OR (Venue_State = 'NT')));

13 Action Statement Create table Booking ( … CONSTRAINT Venue_NameFK FOREIGN KEY (Venue_Name) REFERENCES Venue (Venue_Name) ON DELETE RESTRICT ON UPDATE RESTRICT ); Changes to the Booking table will not alter the Venue table.

14 Create View SELECT Race_Type, Count(*) FROM Race natural join Entry GROUP BY Race_Type; CREATE VIEW LanesNeeded AS SELECT Race_Type, Count(*) FROM Race natural join Entry GROUP BY Race_Type; Crew_BoatCategoryCount Coxed Pair 4 Coxless Double 5 Coxed Quad Scull 6 Coxed Eight 6 Single Scull 11 Coxed Four 3

15 Querying a View Show races where more than one heat will be needed. Select Race_Type, Count(*) from LanesNeeded where count > 8; Crew_BoatCategoryCount Single Scull 11


Download ppt "Database design by Sarah Huynh."

Similar presentations


Ads by Google