You are on page 1of 3

Name:

Id#:
School:

Date:

Database Design Test

Duration 2.5 hours

Save all the statement in one single SQL file called CarTest_yourid#
(substitute your id number for the yourid# part of the file name), in your G:
drive. Run and debug each SQL statement separately within the file. Include
the question numbers as comments throughout the file. Read each question
completely before writing the answer.
Write SQL statements for each of the following.
1. Create a database called CarYourid# (substitute your id number for the
yourid#)
[1 mark]
2. Use your new database.
[1
mark]
3. Create the following tables (primary key fields are underlined). Use char
or varchar for
string fields.
Car(ccode : integer, cmake : string (20) , model : string (20), ctype :
string(20), cyear : integer, AmtinStock: integer, unitcost : numeric
(8,2))
Check that unitcost > 0
[6
marks]
Customer(cnum : integer, fname : string(25), lname : string(25), dob :
date,
straddr : string (50), parish : string(15))
Default parish is St Andrew
marks]

[6

Sale(salenum : integer identity , ccode : integer, cnum : integer,


sdate : date, qty : integer, totalcost : numeric (8, 2) , agent :
string(25), commission : numeric (6,2) )
Default sdate (sale date) is todays date.
Foreign key ccode references Car
Foreign key cnum references Customer
[8
marks]
4. Alter the customer table to include a field called gender. Alter the Sale
table to
remove the field commission. Alter the customer table to change the size
of the field
parish to length 25.
[2+2+2 marks]

5. Insert 5 rows into Car using ccode 100, 101, 102, 103. 104 fill in the other
field values
with your own data you may repeat any data except the primary key
value, put in values for each unitcost.
[5 marks]
Insert 5 rows into the customer table using cnums 10, 20, 30, 40, 50 and
parishes
Kingston, St Catherine, Kingston, St Thomas & Hanover respectively, put in
your own
values for the other fields, values may be repeated.
[5
marks]
Insert 5 rows into Sale using ccode 100, 101, 102, 101 & 104 and cnums
10, 20, 30, 10 &
20 respectively with sale dates Jan 1, 2010, Feb 1, 2010. Jan 1, 2010, May
22, 2011 and
June 1, 2011 respectively. Put values in for the other fields.
[5 marks]
6. Update Car so that the unitcost for ccode 101 and 102 is changed to 1.5M.
[2 marks]
7. Delete customer 40 from the Customer table.
[2
marks]
8. What are the names, ages and addresses of all customers?
[2 marks]
9. Which customers have the letter q at the start of their names?
[2
marks]
10. What is the make, model and type of the most expensive car?
[3 marks]
11. What is the name of the oldest customer?
[3 marks]
12. What are the names of the customers who bought Cars on Jan 1, 2010?
Show the details
of the car they purchased along with their names.
[4 marks]
13. What is the total amount in stock (AmtinStock) for each make of car ?

[4 marks]
14. Display make, model, type, unit cost of the car, qty sold and charge
(calculated as
unit cost * qty) for each sale.
[4
marks]
15. For each customer show how many cars they have purchased.
[4 marks]
As a backup mechanism copy all the code and paste it as text into the body of an email
send email to smcnamarah@gmail.com

AFTER YOUR TEST IS FINISHED DO NOT MODIFY YOUR SQL FILE. IF THE MODIFIED
DATE IS PAST THE TEST TIME YOU WILL BE GIVEN 0%

Thanks for your feedback. Best wishes on the Final Exam.

You might also like