|
http://www.4guysfromrolla.com/webtech/041906-1.shtml
CREATE PROCEDURE DeleteEmployee ( @EmployeeID int )ASBEGIN TRY BEGIN TRANSACTION
-- Start the transaction -- Delete the Employee's phone numbers
DELETE FROM EmployeePhoneNumbers WHERE EmployeeID = @EmployeeID
-- Delete the Employee record DELETE FROM Employees WHERE EmployeeID = @EmployeeID
-- If we reach here, success! COMMITEND TRYBEGIN CATCH -- Whoops, there was an error
IF @@TRANCOUNT > 0 ROLLBACK -- Raise an error with the details of the exception
DECLARE @ErrMsg nvarchar(4000), @ErrSeverity int SELECT @ErrMsg = ERROR_MESSAGE(),
@ErrSeverity = ERROR_SEVERITY() RAISERROR(@ErrMsg, @ErrSeverity, 1)
END CATCH
[ 本帖最后由 tutu 于 2010-1-21 06:31 编辑 ] |
|