USP_AUDIT_PURGE_TABLE
Executes the "Audit Table: Purge" record operation.
Parameters
Parameter | Parameter Type | Mode | Description |
---|---|---|---|
@ID | nvarchar(128) | IN | Input parameter indicating the ID of the record being updated. |
@CHANGEAGENTID | uniqueidentifier | IN | Input parameter indicating the ID of the change agent invoking the update. |
Definition
Copy
CREATE procedure dbo.USP_AUDIT_PURGE_TABLE
@ID nvarchar(128),
@CHANGEAGENTID uniqueidentifier = null
with execute as owner
as
set nocount on;
declare @tbname nvarchar(128);
set @tbname=@ID + 'AUDIT'
--Executing dynamic SQL, verify table exists to prevent injection.
if not exists
(
SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE (TABLE_SCHEMA = 'dbo') AND (TABLE_NAME = @tbname)
)
BEGIN
declare @msg nvarchar(256);
set @msg='The specified table does not exist: ' + @tbname;
RAISERROR(@msg,16,10);
return -300;
END
declare @s nvarchar(256);
set @s='TRUNCATE TABLE dbo.[' + @tbname + '];';
exec(@s);
return 0;