Stored Procedures  «Prev  Next»

Create a User-Defined Stored Procedure Exercise

Objective: Practice creating a user-defined stored procedure.

Exercise Scoring

This exercise is worth a total of 20 points. You will receive full credit for writing a correct Transact-SQL statement that creates the stored procedure described below.

Instructions

Construct a stored procedure named dbo.usp_GetLastName that:
  1. Accepts one input parameter named @EmployeeID of type int
  2. Returns the employee’s last name using a SELECT statement

Assume the table is named dbo.Employees and the relevant columns are EmployeeID and LastName.

Hints

  • Use CREATE OR ALTER PROCEDURE (modern, deployment-friendly syntax).
  • Use SET NOCOUNT ON; inside the procedure body.
  • Your SELECT should filter by EmployeeID = @EmployeeID.

Submitting the exercise

Type or paste your Transact-SQL statement into the text box below, then click Submit to view the results page.

www.sentrypc.com