If your business rules change, you might need to modify your stored procedures, using either Enterprise Manager or Transact-SQL.
As you probably noticed, the
ALTER PROCEDURE
syntax is almost the same as the
CREATE PROCEDURE
syntax.
Therefore, an alternative to modifying your stored procedures is to delete and re-create them. However, if you do so, you will lose all permissions assigned to the stored procedure and any reference to dependency objects. Let us modify the stored procedure that we created in the prior lesson to delete data from the Timesheets table for the employee:
ALTER PROCEDURE usp_DeleteEmployee @EmployeeID int
AS
IF EXISTS (SELECT * FROM employees WHERE EmployeeID
= @EmployeeID)
BEGIN
DELETE
FROM Employees
WHERE EmployeeID = @EmployeeID
DELETE
FROM Timesheets
WHERE EmployeeID = @EmployeeID
END
ELSE
RAISERROR ('Employee ID does not exist', 16, 1)
In the next lesson, you will learn how to delete a stored procedure.