0% found this document useful (0 votes)
104 views

Lab Exercise #7

The document describes a lab exercise involving writing scripts that create and call various stored procedures and functions in SQL. It includes 5 steps: 1) Creating a stored procedure to insert a new department, 2) Creating a function to calculate a student's total course units, 3) Creating a function to calculate a student's total tuition based on whether they are full-time or part-time, 4) Creating a stored procedure to insert a new instructor that validates input, and 5) Creating a stored procedure to update an instructor's annual salary that also validates input. For each step, the student is asked to provide the code and screenshots of testing the procedures and functions.

Uploaded by

Purv Sutariya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
104 views

Lab Exercise #7

The document describes a lab exercise involving writing scripts that create and call various stored procedures and functions in SQL. It includes 5 steps: 1) Creating a stored procedure to insert a new department, 2) Creating a function to calculate a student's total course units, 3) Creating a function to calculate a student's total tuition based on whether they are full-time or part-time, 4) Creating a stored procedure to insert a new instructor that validates input, and 5) Creating a stored procedure to update an instructor's annual salary that also validates input. For each step, the student is asked to provide the code and screenshots of testing the procedures and functions.

Uploaded by

Purv Sutariya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

N01580206 Yug Sutariya

Lab Exercise #7
Grade: 1%
Submission:
1. Save this Lab as Lab7_StudentNumber. For example:
Lab7_N1234567.
2. Perform all the following steps.
3. Take a Screen Capture of each step and insert under each step.
4. Upload Pdf version of your word document in Lab Exercise7
Exercises
1. 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.
Code at least two EXEC statements that test this procedure. (Note that this table doesn’t allow
duplicate department names.)
N01580206 Yug Sutariya
N01580206 Yug Sutariya

2. 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.

Ans :-
N01580206 Yug Sutariya

3. 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 exercise 2, 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 units). (Hint: Use a cross join to work with data in the Students and Tuition tables.)
N01580206 Yug Sutariya

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.

Ans :-
N01580206 Yug Sutariya

4. 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 DateAdded 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 doesn’t accept negative numbers.
Code at least two EXEC statements that test this procedure.

Ans :-
N01580206 Yug Sutariya
N01580206 Yug Sutariya
N01580206 Yug Sutariya
N01580206 Yug Sutariya

5. 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.

Ans :-
N01580206 Yug Sutariya

You might also like