Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In SQL working on how to code stored procedures, functions, and triggers: 1.Write a script that creates and calls a stored procedure named spUpdateInstructor that

In SQL working on how to code stored procedures, functions, and triggers:

1.Write a script that creates and calls a stored procedure named spUpdateInstructor that updates the AnnualSalary column in the Instructors table. This procedure should have one parameter for the instructor ID and another for the annual salary.

If the value for the AnnualSalary column is a negative number, the stored procedure should raise an error that indicates that the value for this column must be a positive number.

Code at least two EXEC statements that test this procedure.

2. Create a trigger named Instructors_UPDATE that checks the new value for the AnnualSalary column of the Instructors table. This trigger should raise an appropriate error if the annual salary is greater than 120,000 or less than 0.

If the new annual salary is between 0 and 12,000, this trigger should modify the new annual salary by multiplying it by 12. That way, a monthly salary of 5,000 becomes an annual salary of 60,000.

Test this trigger with an appropriate UPDATE statement.

3. Create a trigger named Instructors_INSERT that inserts the current date for the HireDate column of the Instructors table if the value for that column is null.

Test this trigger with an appropriate INSERT statement.

4. Create a table named InstructorsAudit. This table should have all columns of the Instructors table. Also, it should have an AuditID column for its primary key and a DATETIME2 column named DateUpdated.

Create a trigger named Instructors_UPDATE. This trigger should insert the old data about the instructor into the InstructorsAudit table after the row is updated and set the DateUpdated column to the current date and time.Then, test this trigger with an appropriate UPDATE statement.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Auditing

Authors: Graham Cosserat

2nd Edition

0470863226, 978-0470863220

More Books

Students also viewed these Accounting questions

Question

Find the value of c such that the domain of f(x)=c - x is [-5, 5].

Answered: 1 week ago

Question

Assess the requirements for strategic LMD

Answered: 1 week ago

Question

How can e-learning benefit organizations and individuals?

Answered: 1 week ago