[SOLVED] Database Design and Analysis. Use the Accidents_2016.csv file below to implement the following steps for your database project.

I need an explanation for this MySQL question to help me study.

Struggling to find relevant content or pressed for time? – Don’t worry, we have a team of professionals to help you on
[SOLVED] Database Design and Analysis. Use the Accidents_2016.csv file below to implement the following steps for your database project.
Get a 15% Discount on this Paper
Order Now
  1. Create a MySQL schema named “accidents.”
  2. Within the accidents schema, create a table named accidents_2016 with the following columns:
    • accident_index as a varchar(13),
    • accident_severity as an int
  3. Within the accidents schema, create a table named vehicles_2016 with the following columns:
    • accident_index as a varchar(13),
    • vehicle_type as a varchar(10)
  4. Within the accidents schema, create a table named vehicle_type with the following columns:
    • vcode int,
    • vtype as a varchar(100)
  5. Next, you will load the data for the three tables.
    • Load the accidents data. Note that @dummy is a placeholder for a column in the .csv file that you want to ignore during the load.
load data local infile '…dataAccidents_2016.csv'
into table accidents_2016
fields terminated by ','
enclosed by '"'
lines terminated by 'n'
ignore 1 lines
(@col1, @dummy, @dummy, @dummy, @dummy, @dummy, @col2
,@dummy, @dummy, @dummy, @dummy, @dummy
,@dummy, @dummy, @dummy, @dummy, @dummy
,@dummy, @dummy, @dummy, @dummy, @dummy
,@dummy, @dummy, @dummy, @dummy, @dummy
,@dummy, @dummy, @dummy, @dummy, @dummy
) 
set accident_index=@col1,accident_severity=@col2;
  • Load the vehicle data.
load data local infile '…dataVehicles_2016.csv'
into table vehicles_2016
fields terminated by ','
enclosed by '"'
lines terminated by 'n'
ignore 1 lines
(@col1, @dummy, @dummy, @col2
,@dummy, @dummy, @dummy, @dummy, @dummy
,@dummy, @dummy, @dummy, @dummy, @dummy
,@dummy, @dummy, @dummy, @dummy, @dummy
,@dummy, @dummy, @dummy, @dummy, @dummy
)
set accident_index=@col1,vehicle_type=@col2;
  • Load the vehicle type data.
load data local infile  '…datavehicle_type.csv'
into table  vehicle_type
fields  terminated by ','
enclosed by  '"'
lines  terminated by 'n'
ignore 1  lines
  1. After the data are loaded, you will perform the analysis. First, find the average accident severity and the number of accidents for vehicles of type motorcycle. Note the performance of your query. Your query may run so slowly that MySQL aborts running completing.
  2. Improve Query Performance
    • Look at the explain tool output and save the results to a graphic file.
    • From the explain results, how many rows have to be read per join?
    • Add an index named “accident_index” of type “index” on the accident_index
    • column in the accidents_2016 table and another index named “accident_index” of type “index” on the vehicles_2106 table.
alter table accidents_2016
add index accident_index (accident_index asc);
alter table vehicles_2016
add index accident_index (accident_index asc);

After adding the indices, rerun the query explanation tool and determine the number of rows to be read per join.

  1. Find the median accident severity.

MySQL does not have a median function so to find the median accident severity, you will have to write a Python script.

  • You’ll need to install Python and the PyMySQL module.
  • Install Python version 2.7 or 3.4 from www.python.org.

To install the PyMySQL module, run the following command in a Windows command prompt after Python has been installed:

python -m pip install  --index-url=https://pypi.python.org/simple/ --trusted-host pypi.python.org PyMySQL

b) Create an accident median table

create  table accident_medians
(
       vtype varchar(100),
       severity int
);
  • Run the following Python script:
import pymysql
myConnection  = pymysql.connect(host='localhost', user='****', passwd='****', db='accidents')
cur = myConnection.cursor()
cur.execute('SELECT vtype FROM vehicle_type WHERE  vtype LIKE "%otorcycle%";')
cycleList = cur.fetchall()
selectSQL = ('''
                SELECT  t.vtype, a.accident_severity
                FROM accidents_2016 AS a
                JOIN vehicles_2016 AS v ON  a.accident_index = v.Accident_Index
                JOIN vehicle_type AS t ON  v.Vehicle_Type = t.vcode
                WHERE t.vtype LIKE %s
                ORDER BY  a.accident_severity;''')
insertSQL = ('''INSERT INTO accident_medians  VALUES (%s, %s);''')
                
for cycle  in cycleList:
                cur.execute(selectSQL,cycle[0])
                accidents = cur.fetchall()
                quotient, remainder =  divmod(len(accidents),2)
                if  remainder:
                                med_sev =  accidents[quotient][1]
                else:
                                med_sev =  (accidents[quotient][1] + accidents[quotient+2][1])/2
                print('Finding median  for',cycle[0])
                cur.execute(insertSQL,(cycle[0],med_sev))
myConnection.commit()
myConnection.close()

Write each query you used in Steps 1 – 8 in a text file. If a query produced a result set, then list the first ten rows of each row set after the query.

Calculate the price
Make an order in advance and get the best price
Pages (550 words)
$0.00
*Price with a welcome 15% discount applied.
Pro tip: If you want to save more money and pay the lowest price, you need to set a more extended deadline.
We know how difficult it is to be a student these days. That's why our prices are one of the most affordable on the market, and there are no hidden fees.

Instead, we offer bonuses, discounts, and free services to make your experience outstanding.
How it works
Receive a 100% original paper that will pass Turnitin from a top essay writing service
step 1
Upload your instructions
Fill out the order form and provide paper details. You can even attach screenshots or add additional instructions later. If something is not clear or missing, the writer will contact you for clarification.
Pro service tips
How to get the most out of your experience with MyCoursebay
One writer throughout the entire course
If you like the writer, you can hire them again. Just copy & paste their ID on the order form ("Preferred Writer's ID" field). This way, your vocabulary will be uniform, and the writer will be aware of your needs.
The same paper from different writers
You can order essay or any other work from two different writers to choose the best one or give another version to a friend. This can be done through the add-on "Same paper from another writer."
Copy of sources used by the writer
Our college essay writers work with ScienceDirect and other databases. They can send you articles or materials used in PDF or through screenshots. Just tick the "Copy of sources" field on the order form.
Testimonials
See why 20k+ students have chosen us as their sole writing assistance provider
Check out the latest reviews and opinions submitted by real customers worldwide and make an informed decision.
Nursing
A-1 service every single time!!!
Customer 452453, July 27th, 2021
Social Work and Human Services
Awesome Work!
Customer 452587, October 20th, 2021
Nursing
Another great paper! Thank you!
Customer 452707, June 16th, 2022
Eng 099
I recveived a B on this paper but I'm not sure why.
Customer 452775, June 18th, 2022
Nursing
Thank you for helping with my assignment.
Customer 452707, July 8th, 2022
Finance
Thank You
Customer 452643, October 24th, 2021
Psychology
The paper is well written and professional. I highly recommend
Customer 452485, August 22nd, 2021
English 101
I'm glad i came to you guys
Customer 452519, May 11th, 2021
Ethics
thank you
Customer 452493, March 15th, 2021
Other
GREAT
Customer 452813, June 20th, 2022
Nursing
This is great! Thank you
Customer 452679, December 16th, 2021
Nursing
Great work! Thank you so much.
Customer 452707, July 15th, 2022
11,595
Customer reviews in total
96%
Current satisfaction rate
3 pages
Average paper length
37%
Customers referred by a friend
OUR GIFT TO YOU
15% OFF your first order
Use a coupon FIRST15 and enjoy expert help with any task at the most affordable price.
Claim my 15% OFF Order in Chat
NEW

Thank you for choosing MyCoursebay. Your presence is a motivation to us. All papers are written from scratch. Plagiarism is not tolerated. Order now for a 15% discount

Order Now