Presentation is loading. Please wait.

Presentation is loading. Please wait.

Jenny Jirathammakul High Distinction Assignment 31061 - Database Principles Autumn, 2007 Melbourne City Toyota.

Similar presentations


Presentation on theme: "Jenny Jirathammakul High Distinction Assignment 31061 - Database Principles Autumn, 2007 Melbourne City Toyota."— Presentation transcript:

1 Jenny Jirathammakul High Distinction Assignment 31061 - Database Principles Autumn, 2007 Melbourne City Toyota

2 : Melbourne City Toyota This database is based on the Melbourne City Toyota website: http://www.melbcitytoyota.com.au/default.cfm?fuseaction=usedcars.dsp_main Allows users to search the website for New Toyotas, Used Cars or Demonstration Cars. The Cars are sorted into Car Brands that is further arranged into the Car Style to make it easier to browse through the different categories. Extras are also included, such as Accessories and Parts, with New Cars if the User wished to look through additional things for a particular car. Enquiries by Users concerning the Cars are sorted by the CarID. This is to ensure that the Users’ enquiries would be specific to the particular car.

3 : Melbourne City Toyota

4 : Entity Relationship Diagram

5 : One to Many Relationship – 1:M CarBrandIDCarBrandCarModelCarMakeCarBody 1ToyotaRAV4CV4WD 2ToyotaCamrySportivoSedan 6HondaAccordEXI 4WSSedan 8LexusIS200SportsSedan 11SuzukiSwiftCinoHatchback CarID CarBrandID* CarYearCarOwnTypeColourKilometresListPriceInternetPriceRegistration N1234512007NewSilver31990 U3689212006UsedLight Gold753243299027777ULS948 U3777112006UsedLight Teal74993599033777UPZ685 N2468922007UsedBlack33000 U3690122004UsedWhite1440642299021540ULJ121 Primary Key Foreign Key* This 1:M relationship shows that one Car Style has one or many cars with that style  CarBrandID 1 & 2 show this association CarStyle Car

6 : Many to Many Relationship – M:M CarIDCarBrandID*CarYearCarOwnTypeColourKilometresListPriceInternetPriceRegistration N1234512007NewSilver31990 U3689212006UsedLight Gold753243299027777ULS948 U3777112006UsedLight Teal74993599033777UPZ685 N2468922007NewBlack33000 U3690122004UsedWhite1440642299021540ULJ121 CarID*AccessoryID*PartsID* N1234511 20 N2468992 130 N24689140 N54321141 AccessoryIDAccessoryNameAccessoryPrice 1Safety Pack750 2Metallic Paint300 9New Camry Bootlip Spoilers550 13Leather Trim1500 14Moonroof1650 Car Extras Accessory This M:M relationship shows that many cars can have many accessories because: A Car can have many Accessories and; An Accessory can be apart of many Cars

7 : Simple Query of a Single Table CarBrandIDCarBrandCarModelCarMakeCarBody 6HondaAccordEXI 4WSSedan 7HondaHRVSport4WD select * from carstyle where carbrand = ‘Honda’ order by carbrandid; List all cars manufactured by Honda select accessoryname, accessoryprice from accessory where accessoryname like ‘G%’; Show all Accessory Names starting with ‘G’ AccessoryNameAccessoryPrice Genuine Toyota Park Assist595 Genuine Toyota Protection Packs180 Genuine Toyota Satellite Navagation System3500

8 : Query – Natural Join select enquiriesid, carid, username, carowntype, question from users natural join enquiries natural join car where carid = ‘U37975’; Show EnquiriesID, CarID, UserName, CarOwnType and Question for the car ‘U37975’ EnquiriesIDCarIDUserNameCarOwnTypeQuestion 3U37975NicoleUsed Would the car get the same kind of since as a newly bought Toyota since it has only been used for a while 1U37975TonyUsedWhat is the average Fuel consumption rate for this car

9 : Cross-Product Join select carid, carbrand, carmodel, carmake, caryear from car, carstyle where car.carbrandid = carstyle.carbrandid and carbody = ‘Hatchback’; Show the carid, carbrand, carmodel and carmake, caryear of all cars that are hatchbacks CarIDCarBrandCarModelCarMakeCarYear N12345SuzukiSwiftCino1998 U36892ToyotaYarisYR2007

10 : Group By Find out how many CarBrandIDs have registrations (that is, their registration is not null) select carbrandid, count(*) from car where registration is not null group by carbrandid; CarBrandIDCount 142 131 111 101 91 81 71 61 51 21 12

11 : Group By with Having Display car colours that have more than one car having that colour select colour, count(*) as total from car group by colour having count(*) > 1; ColourTotal Silver3 Black3 White4

12 : Sub-Query List the carid, carbrand, carmodel, carmake, kilometres of the car with the minimum amount of kilometres driven that was manufactured before the year 2000 select carid, carbrand, carmodel, carmake, kilometres from car natural join carstyle where caryear < 2000 and kilometres <= (select min(kilometres) from car where caryear < 2000); CarIDCarBrandCarModelCarMakeKilometres U38412SuzukiSwiftCino95876

13 : Self-Join List the CarID of cars that have the same colour ‘Black’ select c1.colour, c2.carid from car c1, car c2 where c1.carid = ‘U38523’ and c1.colour = c2.colour; ColourCarID BlackN24689 BlackU38523 BlackU37947

14 : Data Integrity – CHECK Statements These CHECK statements make sure that the values entered into the INSERT statements do not breach the restrictions placed upon them CONSTRAINTCHECK CONSTRAINT Car_Year CHECK ((CarYear > 1900) AND (CarYear <= 2007)), CONSTRAINTCHECK CONSTRAINT Car_ListPrice CHECK (ListPrice > 0), CONSTRAINTCHECK CONSTRAINT Car_InternetPrice CHECK ((InternetPrice > 0) OR (InternetPrice IS NULL)) This CHECK statements make sure that the values entered into the INSERT statements include only these types of values, that is, the only values that can be entered into Car Brand are only those types of car brands to ensure that misspellings do not occur CONSTRAINTCHECK CONSTRAINT CarStyle_Brand CHECK (CarBrand IN ( 'Alfa Romeo','Audi','BMW','Chrysler','Citroen', 'Daewoo','Daihatsu','Ford','Holden','Honda', 'Hyundai','Isuzu','Jeep','Land Rover','Lexus', 'Mazda','Mercedes-Benz','Mitsubishi','Nissan', 'Peugeot','Proton','Renault','Saab','Smart', 'Subaru','Suzuki','Toyota','Volkswagen','Volvo')) Check Statements prevents the SQL from creating data that does not conform to the guidelines that have been put into place and an error would thus occur because of a breach of the contraints

15 : Action Statements – ON DELETE RESTRICT “ON DELETE RESTRICT” prevents the deletion of data that is being used by other categories in another table These Restrictions prevent the deletion of AccessoryIDs and PartsIDs if they are currently being used by other categories in another table CONSTRAINT ExtrasFK_aid FOREIGN KEY (AccessoryID) REFERENCES Accessory (AccessoryID) ON DELETE RESTRICT ON UPDATE CASCADE, CONSTRAINT ExtrasFK_pid FOREIGN KEY (PartsID) REFERENCES Parts (PartsID) ON DELETE RESTRICT ON UPDATE CASCADE

16 : Action Statements – ON DELETE CASCADE “ON DELETE CASCADE” allows data to be deleted from a table that will delete itself in another table as well This deletion of CarID in a table will also be deleted in the extras table also CONSTRAINT ExtrasFK_cid FOREIGN KEY (CarID) REFERENCES Car (CarID) ON DELETE CASCADE ON UPDATE CASCADE,

17 : Creating a View create view specs (carid, year, brand, model, make, kms, owntype, rego) as select carid, caryear, carbrand, carmodel, carmake, kilometres, carowntype, registration from car, carstyle where car.carbrandid = carstyle.carbrandid and carbody = ‘4WD’; Create a view that shows the car style, year, kilometres, ownership type and registration of 4WDs select * from specs; CarIDYearBrandModelMakeKmsOwnTypeRego N123452007ToyotaRAV4CVNew U379752004FordTerritoryTS47088UsedSZS937 U386011999HondaHRVSport123000UsedPUR303 U368922006ToyotaRAV4CV75324UsedULS948 U377712006ToyotaRAV4CV7499UsedUPZ685

18 : Querying a View select * from specs where brand <>‘Toyota’; Show all 4WDs that are not Toyota from the created view ‘specs’ CarIDYearBrandModelMakeKmsOwnTypeRego U379752004FordTerritoryTS47088UsedSZS937 U386011999HondaHRVSport123000UsedPUR303


Download ppt "Jenny Jirathammakul High Distinction Assignment 31061 - Database Principles Autumn, 2007 Melbourne City Toyota."

Similar presentations


Ads by Google