Code:
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
ALTER PROCEDURE [dbo].[fsAction_d]
@ActionIdentifier int
AS
/******************************************************************/
/* Delete procedure returns: */
/* a) -999 if an error occurred */
/* b) The number of records deleted (0 or 1) */
/******************************************************************/
/******************************************************************/
/* IMPORTANT NOTE!!! */
/* Do not insert any DML statements (SELECT, INSERT, UPDATE */
/* DELETE, OPEN CURSOR, or FETCH) before the following */
/* section of code (labeled 'transaction mgt'). In */
/* chained transaction mode, any DML statement (including */
/* SELECTs) will start a transaction if none currently */
/* exists, and will increment the value of @@trancount! */
/******************************************************************/
DECLARE @_error int
DECLARE @_rowcount int
DECLARE @ret_val int
DECLARE @i_started_tran int /* transaction mgt */
DECLARE @rollback_needed int /* transaction mgt */
IF @@trancount = 0 /* transaction mgt */
BEGIN /* transaction mgt */
BEGIN TRANSACTION /* transaction mgt */
SELECT @i_started_tran = 1 /* transaction mgt */
END /* transaction mgt */
ELSE /* transaction mgt */
SELECT @i_started_tran = 0 /* transaction mgt */
SELECT @rollback_needed = 0 /* transaction mgt */
/******************************************************************/
/* SELECTs and other DML statments can begin after this point */
/******************************************************************/
SET NOCOUNT ON
SELECT @ret_val = 0
[highlight]
/*********** delete user table record *****************/
DELETE Action
WHERE
@ActionIdentifier = ActionIdentifier
[/highlight]
SELECT @_error = @@error, @_rowcount = @@rowcount
IF (@_error <> 0)
BEGIN
SELECT @ret_val = (-999)
RAISERROR ('Delete failed in procedure fsAction_d ', 16, 1)
SELECT @rollback_needed = 1
GOTO label_return
END
ELSE
BEGIN
SELECT @ret_val = @_rowcount
END
label_return:
IF @i_started_tran = 1 /* transaction mgt */
IF @rollback_needed = 1 /* transaction mgt */
BEGIN /* transaction mgt */
ROLLBACK TRANSACTION /* transaction mgt */
RETURN @ret_val /* transaction mgt */
END /* transaction mgt */
ELSE /* transaction mgt */
BEGIN /* transaction mgt */
COMMIT TRANSACTION /* transaction mgt */
RETURN @ret_val /* transaction mgt */
END /* transaction mgt */
ELSE /* transaction mgt */
RETURN @ret_val /* transaction mgt */
I have been given a client database to work with and may need to use the following code. This appears to be some of generic delete function. I do not understand at all how this works. Can someone enlighten me about the highlighted area? On the "DELETE Action" line, Action is in BLUE indicating that it is a reserved word on SQL 2005. I can find no reference to this syntax.