Answered step by step
Verified Expert Solution
Question
1 Approved Answer
HW EXERCISES: PROCEDURES, FUNCTIONS, TRIGGERS In this exercise you will create scripts in the Murach College database. 1 . Write a script that creates and
HW EXERCISES: PROCEDURES, FUNCTIONS, TRIGGERS
In this exercise you will create scripts in the Murach College database.
Write a script that creates and calls a stored procedure named spInsertDepartment. First, code a statement that creates a procedure that adds a new row to the Departments table. To do that, this procedure should have one parameter for the department name.
Please paste your SQL stored procedure here.
Code at least two EXEC statements that test this procedure. Note that this table doesnt allow duplicate department names.
Write a script that creates and calls a function named fnStudentUnits that calculates the total course units of a student in the StudentCourses table. To do that, this function should accept one parameter for the student ID and it should return the sum of the course units for the student.
The SELECT statement that calls the function should return the StudentID from the StudentCourses table, the CourseNumber and CourseUnits from the Courses table, and the value return by the fnStudentUnits function for that student.
Please paste your script for your function here.
Please paste your SELECT statement here.
Write a script that creates and calls a function named fnTuition that calculates the total tuition for a student. To do that, this function should accept one parameter for the student ID it should use the fnStudentUnits function that you created in step and it should return the value of the tuition for that student depending on whether the student is fulltime more than nine units or parttime nine or fewer unitsHint: Use a cross join to work with data in the Students and Tuition tables.
The SELECT statement that calls the function should return the StudentID from the Students table, the value returned by the fnStudentUnits function for that student, and the value returned by the fnTuition function for that student. Return only rows for students taking one or more units.
Please paste your script for your function here.
Please paste your SELECT statement here.
Write a script that creates and calls a stored procedure named spInsertInstructor that inserts a row into the Instructors table. This stored procedure should accept one parameter for each of these columns: LastName, FirstName, Status, DepartmentChairman, AnnualSalary, and DepartmentID.
This stored procedure should set the HireDate column to the current date.
If the value for the AnnualSalary column is a negative number, the stored procedure should raise an error that indicates that this column doesnt accept negative numbers.
Code at least two EXEC statements that test this procedure.
Please paste the script for your procedure here.
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.
Please paste your stored procedure here.
Create a trigger named InstructorsUPDATE 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 or less than
If the new annual salary is between and this trigger should modify the new annual salary by multiplying it by That way, a monthly salary of becomes an annual salary of
Test this trigger with an appropriate UPDATE statement
Please paste your trigger here.
Create a trigger named InstructorsINSERT 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.
Please paste your trigger here.
Please paste your INSERT statement here.
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 DATETIME column named DateUpdated.
Create a trigger named InstructorsUPDATE. 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.
Please the code for creating the table here.
Please paste the code for your trigger here.
Please paste your UPDATE statement here.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started