﻿EXEC dev.sp_Global_GenerateAsyncAuditTriggerAll
GO

ALTER QUEUE auditLog.[AuditQueue]
WITH ACTIVATION
( 
    STATUS = ON,
    PROCEDURE_NAME = auditLog.usp_AuditProcessing,
    MAX_QUEUE_READERS = 10,
    EXECUTE AS 'Kreta_tech_user'
);

GO

ALTER QUEUE auditlog.AuditQueue WITH STATUS = ON;
GO

DROP PROCEDURE IF EXISTS dev.sp_Global_GenerateAsyncAuditAuditProcessing;
GO
DROP PROCEDURE IF EXISTS dev.sp_Global_GenerateAsyncAuditAuditProcedure;
GO
DROP PROCEDURE IF EXISTS dev.sp_Global_GenerateAsyncAuditAuditProcedureAll;
GO

DECLARE @sql nvarchar(max) = '';

SELECT @sql += N'DROP PROCEDURE IF EXISTS auditlog.' + ROUTINE_NAME + ';' + char(13) + char(10)
FROM INFORMATION_SCHEMA.ROUTINES r
WHERE r.ROUTINE_SCHEMA = N'auditlog' 
  AND r.ROUTINE_NAME like N'usp_AsyncAudit%';

EXEC sys.sp_executesql @sql
GO
