Section B- Practical (70 Marks)
(NOTE: Use SQL Server Management System (SSMS) on your computer for this section)
Instructions: Copy and Paste your final code onto notepad and save it on the exam drive (z). The
drive is the drive with your student number.
Question 1
Mewiliko Car Dealership (MCD) is a Namibian owned company and it comprises of. many
departments such as HR, Auxiliary department etc... The auxiliary department is interested in
tracking cars they buy. Create a simple database called MCD and a table called Cars. The columns in
the Cars table are named registration ID, Car Name, Price, and Car Description (gives the full details
of the car including make, model and year). The registration ID column is the primary key of the
table. Use the appropriate data types. Only the Price and Car Description columns can have no data
when a row is inserted or changed. Create a statement to check if the table has been created. [8
Marks]
Question 2
Write a statement to create a procedure with input parameters which adds new Car details records
(values of your choice) to the Car table created in question 1. Keep the values for the Car Price, Car
Description null. The procedure should have a condition to check if the car exist already and print
message 'This car already exist’.
[8 Marks]
Question 3
Write a query to invoke your procedure in Question 2 and adds four (4) rows to the dbo.Cars table.
Show all the values that are passed to the procedure to insert the four rows of data. [2 Marks]
Question 4
Create a stored procedure name sp_countcars, which accepts an input parameter named @Carlabel
and returns the total number cars based on the car Name. The output parameter should be named
carcount. The stored procedure executes SELECT statements based on the table named Cars created
in question 1. The columns registration ID, Car Name, and Car Description should be shown in the
output. Create a statement to invoke the procedure.
[8 Marks]
Question 5
Write a stored procedure that checks if the average car price is less than $300 000, introduce the
WHILE loop that doubles the prices and then selects the maximum price. If the maximum price is less
than or equal to $500 000, the WHILE loop restarts and doubles the prices again. If the average price
is greater than 300k while the max is still less than 500000, This loop continues doubling the prices
until the maximum price is greater than $500 000 and then exits the WHILE loop. [7 Marks]
Question 6
Write a statement to create a trigger to restrict updates on the CarName column in the dbo.table
created in question 1. Print a message 'Updates to Car Name require DBA involvement.’
[5 Marks]