” FIT2094程序 写作、 辅导Databases程序FIT2094 Databases2020 Semester 1Assignment 2 – SQL – Traffic Demerit System (TDS)Assignment weighting 15% – Lecturer in Charge: Minh LeThe local state government wishes to develop a database to record the details ofon-the-spot traffic offences incurred by drivers. When a driver commits an offence theyare stopped and booked on the spot by a police officer and provided with an offencenotice. Offences cause drivers to incur demerit points which accumulate against thedrivers licence.The system records the details of all registered vehicles driven in the local governmentarea. A vehicle is identified by a Vehicle Identification Number (VIN). Background readingon a VIN is available from several sites such as AutoCheck . Other attributes recorded for avehicle are the vehicles year of manufacture, main colour, model name, manufacturername and vehicle type.Drivers are identified by their licence number. Other attributes recorded for a driver are thedrivers mobile number, first name, last name, residential address, date of birth and expirydate for the licence. It is assumed for this task that each driver has a mobile number andthat number will be unique.Each demerit (potential driving offence) is identified by a demerit code. A description of thedemerit and the number of points incurred for that demerit are also recorded. For example,the demerit with code 108, has a description of Failing to give way, or stop, or remainstopped and results in 3 demerit points being incurred by the driver.Each traffic offence by a driver is identified by an offence number. The location of theoffence and the date and time at which the offence occurred is also stored. In somecircumstances when a driver is stopped by a police officer, for example, a speedingoffence, the police officer may also identify other offences such as Driving contrary to amajor defect notice. Each offence recorded has a unique offence number and is for onlyone particular demerit. The police officer who issued the offence is also recorded.Page 1 of 15FIT2094作业 写作、 辅导Databases作业、 写作SQL语言作业、 辅导SQL程序设计作业Once a driver has accumulated 12 demerit points over a period of three years the driverslicence is suspended for a period of 6 months. When an offence committed by a driver isadded to the system by the police officer, the system at that time will determineautomatically if the licence should be suspended or not. When this occurs the driverslicence is suspended from the date recorded for the offence which caused the points toequal or exceed the permitted maximum points. The date at which the suspension beganand the date at which it ends are to be stored in the system. The driver, if suspended, isnot allowed to drive and driving while suspended will lead to a criminal charge and maycause the driver to be jailed.After a drivers suspension ends, their total demerit points are reset to zero and they beginaccumulating points again. For any previously suspended driver, to determine the newsuspension date, the system will calculate the accumulated demerit points from the datetheir last suspension ended.Police officers are identified by an officer id. The system only records the officers firstname and last name.A data model has been created for Traffic Demerit System and is shown below (it is alsoavailable from Moodle):TDS Data ModelFor this assignment, you will populate these tables with appropriate test data and write theSQL queries specified below. You must ensure that any activities you need to carry out in thedatabase to complete the assignment conform to the requirements of the data modeldisplayed above.Page 2 of 15The schema/insert file for creating this model is available in the archive ass2-student.zip -this file creates the Traffic Demerit System tables and populates several of the tables – youshould read this schema carefully and be sure you understand the various datarequirements. You must not alter the schema file in any manner, it must be used assupplied . This schema file contains a single commit after the inserts have completed sincethis is setting up an initial state of the database for you to work with, you should not use thisas your method of approach.IMPORTANT points for you to observe, when completing this assignment, are:1. The ass2-student.zip archive also contains four SQL scripts for you to code youranswers in, you should ensure these files are regularly pushed to GitLab serverso a clear development history is available for the marker to verify. In each file,you must fill in the header details with your name and student ID before beginningany work. Your script files must not include any SPOOL or ECHO commands .Although you might include such commands when testing your work they must beremoved before submission (a 5 mark grade penalty will be applied if yourdocuments contain spool or echo commands)2. You are free to make assumptions if needed. However, your assumptions mustalign with the details here and in the assignment 2 forum and must be clearlydocumented (see the required submission files).REMEMBER you must keep up to date with the Moodle assignment 2 forum wherefurther clarifications may be posted (this forum is to be treated as your client).Please be careful to ensure you do not post anything which includes yourreasoning, logic or any part of your work to this assignment forum as doing soviolates Monash plagiarism/collusion rules.3. Queries that use subqueries and SQL conditions unnecessarily to get required datawill be penalised . Views must not be used in arriving at any solutions for the tasksyou are required to complete as part of this assessment.4. In handling dates, the default date format must not be assumed; you must makeuse of the TO_DATE and TO_CHAR functions in all date situations . Failure to doso will incur a 50% grade penalty for questions involving dates.5. In completing the following tasks, you should design your test data so that youalways get output for the SQL scripts/queries specified below – this may requireyou to add further data as you move through completing the required tasks. Queriesthat are correct but do not produce any output (no rows selected message)using your test data will lose 50% of the marks allocated , so you should carefullycheck your test data and ensure it thoroughly validates your SQL queries.You may need to rerun the schema, especially when you have been experimenting withyour solutions and may have corrupted the database unintentionally. If you suspect thatthere might be such problems, simply rerun the schema. The schema includes theappropriate drop commands at the head of the file.Page 3 of 15Assignment TasksUsing the supplied schema file (tds_ass2_schm_insert.sql) create the tables for theTraffic Demerit System and insert the supplied values. This provides you with a startingpoint for the following tasks.TASK 1: Data Manipulation (23 marks):(a) Load selected tables with your own additional test data using the suppliedQ1a-tds-insert.sql script file, and SQL commands which will insert, as a minimum,the following sample data -● 20 OFFENCES● 3 SUSPENSIONSPlease note, these are the minimum number of entries you must insert ; you areencouraged to insert more to provide a richer data set to draw from.For this task only , data that you add in the database should follow the rules mentionedbelow:1. The primary key values for this data should be hardcoded values (i.e., NOTmake use of sequences) and must consist of values below 100.2. Offences that you add must involve at least 12 different drivers.3. You must not add any offences for the following driver:● Lion Lawless of 72 Aberg Avenue Richmond South 3121 (Licenceno.: 100389)4. Dates used must be chosen between the 1st January 2016 and 30th June2019.5. For each year from 2016 to 2019, you should add at least 4 offences.6. The suspensions you add in the database should not be in just one year,e.g., you should not add all the suspensions in 2018.7. The suspensions you add in the database should not belong to just onedriver, e.g., you should not add all the suspensions for the driver with licencenumber 100100.8. A suspended driver cannot incur extra offences under this system whilesuspended. If a driver commits a driving offence while suspended theirvehicle is impounded and they are sent before the court (this means youmust not add an offence to a suspended driver until their suspension periodhas expired).Page 4 of 159. The supplied trigger shows the current total demerit points for a driver whenyou insert a new offence . You will need to run your inserts one by one inyour offence date order, taking appropriate action if the drivers accumulatedpoints pass the 12 demerit point threshold. Any offence that you add, andany appropriate action that you may have to take as a result of the additionof the new offence, must be managed as a single transaction.For this task ONLY , you can look up and include values for the loadedtables/data directly where required. However, if you wish, you can still useSQL to get any non-key values.You are reminded again that in carrying out this task you must not modify anydata or add any further data to the tables which were previously populated bythe supplied schema file.[14 marks]For all subsequent questions (Q1b onwards) you are NOT permitted to manually :● lookup a value in the database, obtain its primary key or the highest/lowest value ina column, or● calculate values external to the database, e.g., on a calculator and then use suchvalues in your answers.You must ONLY use the data as provided in the text of the questions . Where aparticular case (upper case, lower case, etc.) for a word is provided you must only usethat case . You may divide names such as Zora Mandrey into the first name of Zora and alast name of Mandrey if required. Failure to adhere to this requirement will result in amark of 0 for the relevant question .At any point in your solution, when inserting an offence you must ensure thatSET SERVEROUTPUT ON;has been run in your SQL session so that you receive visual feedback from thecheckPointsAccumulated trigger.Page 5 of 15(b) For the following tasks, your SQL must correctly manage transactions and usesequences to generate new primary keys for numeric primary key values (underno circumstances may a new primary key value be hardcoded as a number or value).Your answers for these tasks must be placed in the supplied SQL ScriptQ1b-tds-dm.sqlYou are reminded again that queries that use subqueries and SQL conditionsunnecessarily to get required data will be penalised.(i) Create a sequence which will allow entry of data into the OFFENCE table – thesequence must begin at 100 and go up in steps of 1 (i.e., the first value is 100, thenext 101, etc.)[1 mark](ii) Lion Lawless of 72 Aberg Avenue Richmond South 3121 (Licence no.: 100389)has been very inconsiderate of others on the road over the years and hascommitted several offences that have been booked by highly vigilant TDS officersat various different locations. Lion Lawless was riding the same motorbike, a 1994Red Yamaha FZR600 (JYA3HHE05RA070562) at the time of committing theseoffences. Lion Lawless has only committed the offences listed below. The details ofthe bookings for Lion are as follows:● 10-Aug-2019 08:04 AM booked for traffic offence Blood alcohol charge bypolice officer Dolley Hedling (10000011)● On 16-Oct-2019 9:00 PM booked for traffic offence Level crossing offenceby police officer Geoff Kilmartin (10000015)● On 7-Jan-2020 7:07 AM booked for traffic offences Exceeding the speedlimit by 25 km/h or more by police officer Geoff Kilmartin (10000015)Take the necessary steps in the database to record these offences.[5 marks](iii) Lion Lawless of 72 Aberg Avenue Richmond South 3121 (Licence no.: 100389)had appealed against the Exceeding the speed limit by 25 km/h or more offencehe has been alleged to have committed on 07-Jan-2020 at 7:07 AM.After careful consideration and taking into account that speed guns at times are notvery accurate, TDS has decided to lessen the offence to Exceeding the speed limitby 10 km/h or more but less than 25 km/h but has strongly warned Lion Lawless tobe more careful in future. Take the necessary steps in the database to record thischange.[3 marks]Page 6 of 15TASK 2: SQL Queries (55 marks):Your answers for these tasks must be placed in the supplied SQL Script Q2-tds-queries.sqlANSI joins must be used where two or more tables are to be joined , under nocircumstances can implicit join notation be used – see the week 7 workshop slide 22and tutorial(i) Show the demerit points and demerit description for all the demerits that either containsthe word heavy or Heavy or start with the word Exceed in the description. The columnheadings in your output should be renamed as Demerit Points and Demerit Description.The output must be sorted in ascending format by demerit points and where two demeritshave the same points sort them in ascending format of demerit description. Your outputmust have the form shown below.[4 marks](ii) For all Range Rover and Range Rover Sport models, show the main colour, VINand manufacture year for all the vehicles that were manufactured from 2012 to 2014. Thecolumn headings in your output should be renamed as Main Colour, VIN and YearManufactured. The output must be sorted by manufacture year in descending format andwhere more than one vehicle was manufactured in the same year sort them by colour inascending format. Your output must have the form shown below.[4 marks]Page 7 of 15(iii) Show the driver licence number, full name (firstname and lastname together), date ofbirth, full address (street, town and postcode together), suspension start date andsuspension end date for all the drivers who have had their licence suspended in the last 30months. You need SQL to calculate 30 months from the day this query would be executedby the user. The column headings in your output should be renamed as Licence No.,Driver Fullname, DOB, Driver Address, Suspended On and Suspended Till. The outputmust be sorted by licence number in ascending format and where there is one licencenumber suspended more than once sort them by suspended date in descending format.Your output must have the form shown below. Your output can clearly be different from thefollowing output.[5 marks](iv) TDS would like to find out if there is any correlation between different months of a yearand demerit codes so you have been assigned to generate a report that shows for ALL thedemerits, the code, description, total number of offences committed for the demerit codeso far in any month (of any year) and then the total of offences committed for the demeritcode in each month (of any year) . The column headings in your output should be renamedas Demerit Code, Demerit Description, Total Offences (All Months), and then the first threeletters of each month (with first letter in uppercase). The output must be sorted by TotalOffences (All Months) column in descending format and where there is more than onedemerit code with the same total, sort them by demerit code in ascending format. Youroutput must have the form shown below. Your output can clearly be different from thefollowing output.[7 marks]Page 8 of 15(v) Find out which manufacturers vehicles are involved in the highest number of offenceswhich incur 2 or more demerit points. Show the manufacturer name and the total numberof offences that the manufacturers vehicles are involved in. The column headings in youroutput should be renamed as Manufacturer Name and Total No. of Offences. The outputmust be sorted by Total No. of Offences column in descending format and where there ismore than one manufacturer with the same total, sort them by manufacturer name inascending format. Your output can clearly be different from the following output.[7 marks](vi) Find out the drivers who have been booked more than once for the same offence byan officer with the last name as that of their last name. Show the driver licence number,driver full name (firstname and lastname together, officer number, officer full name(firstname and lastname together). The column headings in your output should berenamed as Licence No., Driver Name, Officer ID, Officer Name. The output must besorted by driver licence number column in ascending format.[7 marks]Page 9 of 15(vii) For each demerit code for which an offence has been recorded, find out the driver/swho has/have been booked the most number of times. Show the demerit code, demeritdescription, driver licence number, driver full name (firstname and lastname together) andthe total number of times the driver has been booked in the output. The column headingsin your output should be renamed as Demerit Code, Demerit Description, Licence No.,Driver Fullname and Total Times Booked. The output must be sorted by demerit code inascending format and where for one demerit there is more than one driver booked themost number of times sort them by licence number in ascending format. Your output musthave the form shown below. Your output can clearly be different from the following output.[8 marks]Page 10 of 15(viii) For each region, show the number of vehicles manufactured in the region and thepercentage of vehicles manufactured in the region. The last row of the output shows thetotals – the second column which shows the total number of vehicles manufactured in allregions (which is the total of all the individual totals in this column) and the third column ofwhich shows the total percentage of vehicles manufactured in all the regions (which is thetotal of all the individual percentages in this column). The first character of the VINrepresents the region where the vehicle was manufactured. In your SQL, you need todetermine the region in which the vehicle was manufactured using the following table(Source: wikibooks ).First Character of VIN RegionFrom A to C AfricaFrom J to R AsiaFrom S to Z EuropeFrom 1 to 5 North AmericaFrom 6 to 7 OceaniaFrom 8 to 9 South AmericaAnything else UnknownThe column headings in your output should be renamed as Region, Total VehiclesManufactured and Percentage of Vehicles Manufactured. The output must be sorted byTotal Vehicles Manufactured in ascending format and where there is more than one regionwith the same total, sort them by region in ascending format . Your output must have theform shown below.[13 marks]Page 11 of 15TASK 3: Design Modifications (22 marks):Your answers for these tasks must be placed in the supplied SQL Script Q3-tds-mods.sqlThese tasks should be attempted only after task 1 and task 2 have beensuccessfully completed. They are to be completed on the live database ie. thedatabase with the data loaded from your previous work. For this question, you must notmake use of any PL/SQL .(i) TDS would like to be able to easily determine the total number of times each policeofficer has booked a driver for a traffic offence. Add a new attribute which will record thenumber of times each officer has booked drivers.This attribute must be initialised to the correct current number of times each officer hasbooked drivers based on the data which is currently stored in the system.[4 marks](ii) The problem TDS might face with the current database is if an offence is revoked forsome valid reason, it is impossible for them to keep the offence information for the revokedoffence in the database. TDS would like to fix this problem such that they are able to keepinformation about a revoked offence along with the other required information such aswhen it was revoked, who revoked the offence and the reason for revocation. For quickaccess, it has been decided that a column is also required to indicate Yes or No if anoffence has been revoked or not. There will always be only one reason that can beassociated with a revocation. TDS will not be able to add all the reasons for a revocation ofthe offences initially and so your solution should allow them to add new reasons as andwhen there is a need. At this stage, the only reasons for revocation of an offence TDS isinterested in recording are First offence exceeding the speed limit by less than 10km/h(FOS), Faulty equipment used (FEU), Driver objection upheld (DOU), Court hearing (COH),and Error in proceedings (EIP) . Each reason code will have exactly 3 letters.When providing the solution, you must consider the following:a. only around 1% of offences recorded are revoked and there can be hundreds ofthousands of offences in the offence table,b. all existing offences, after implementing this requirement, must automatically berecorded as not revoked,c. appeals are made by completing a paper form and sending the completed form toTDS either by fax or mail and, at this stage, there is no need to record unsuccessfulappeals in the database.[6 marks]Page 12 of 15(iii) TDS has found that having just the vehicles main colour in the database, in some cases, isinadequate in helping identify a vehicle that has been involved in a traffic offence. As aconsequence, they have decided to now also record if any outer part other than the body of thevehicle is of a different colour. At this stage, the only other parts TDS is interested in recording thecolour of are the Spoiler (SP), Bumper (BM) and Grilles (GR) but this may change if the needarises and so it should be able to be changed easily. Each outer part code will have exactly 2letters. Where the colour of grilles, spoiler (if any) or Bumper is the same as that of the bodycolour, there is no Need to record anything in the database.TDS is also intending to find a solution such that new colours can be easily introduced when amanufacturer releases a new colour. Each colour must be identified by a unique colour number(which is auto-generated by the system) and has its colour description recorded as shown below(sample data only shown).This data must be collected from the current state of the vehicle table via SQL only (you cannotassume the presence of any particular colour) . Subsequent colours will be added directly to thiscollection via INSERT statements. You are reminded again that you must not make use ofany PL/SQL in solving this task.At this stage, the vehicles that have different colours for some of the above-mentioned outer partsare as follows:Vehicle 1:VIN: ZHWEF4ZF2LLA13803Manufacturer Name: LamborghiniModel Name: Huracan EVOVehicle main colour: GreySpoiler colour: BlackBumper colour: GreyGrilles colour: MagentaPage 13 of 15Vehicle 2:VIN: ZHWES4ZF8KLA12259Manufacturer Name: LamborghiniModel Name: Huracan PerformanteVehicle main Colour: BlackSpoiler colour: YellowBumper colour: BlueGrilles colour: BlackChange the database to meet these requirements. Note: You should only use the necessary DDLand DML statements to achieve these requirements.[12 marks]SUBMISSION REQUIREMENTSDue Date: Friday 12th June 2020 at 5 PM (Week 12)Please note, if you need to resubmit, you cannot depend on your tutors availability, for this reason,please be VERY CAREFUL with your submission. It is strongly recommended that you submitseveral hours before this time to avoid such issues.For this assignment there are four files you are required to submit:● Q1a-tds-insert.sql● Q1b-tds-dm.sql● Q2-tds-queries.sql● Q3-tds-mods.sqlIf you need to make any comments to your marker/tutor please place them at the head of each ofyour solution scripts in the Comments for your marker: section.Do not zip these files into one zip archive, submit four independent SQL scripts. The individual filesmust also have been pushed to the FIT GitLab server with an appropriate history as you developedyour solutions.Late submission will incur penalties as outlined in the unit guide.Page 14 of 15Please note we cannot mark any work on the GitLab Server, you need to ensure that yousubmit correctly via Moodle since it is only in this process that you complete the required studentdeclaration without which work cannot be assessed.It is your responsibility to ENSURE that the files you submit are the correct files – westrongly recommend after uploading a submission, and prior to actually submitting, that youdownload the submission and double check its contents.Your assignment MUST Show a status of Submitted for grading before it will be marked.If your submission shows a status of Draft (not submitted) it will not be assessed and will incurlate penalties after the due date/time.Please carefully read the documentation under the Assignment Submission on the MoodleAssessments page which covers things such as extensions and resubmission.Criteria for marking:Submissions will be graded on:● the correct application of relational database principles,● the correct handling of transactions and the setting of appropriate transaction boundariesi.e. correct placement of commits, and● the correct application of SQL statements and constructs to:○ populate tables,○ modify existing data in tables,○ prepare reports by Retrieving the required data in the required format, and○ modify the live database structure to meet the expressed requirements (includingappropriate use of constraints). In making these modifications there must be no lossof existing data or data integrity within the database.Submissions will be grade penalised if they:● contain SET ECHO or SPOOL commands● make use of views● use subqueries and SQL conditions unnecessarily,● do not use to_char/to_date where appropriate in handling dates,● do not have an appropriate development history on the FIT GitLab server for all source files (atleast three pushes required).Page 15 of 15如有需要,请加QQ:99515681 或邮箱:99515681@qq.com
“
添加老师微信回复‘’官网 辅导‘’获取专业老师帮助,或点击联系老师1对1在线指导。