TR_ADHOCQUERY_DELETE_IDSET
Definition
Copy
CREATE trigger [dbo].[TR_ADHOCQUERY_DELETE_IDSET] on [dbo].[ADHOCQUERY] with execute as owner AFTER DELETE as
set nocount on
declare @AdHocQueryID uniqueidentifier
declare @Format smallint
-- declare a cursor that returns all of the deleted queries
declare deleted_query_cursor cursor local FAST_FORWARD for
select ID from deleted
OPEN deleted_query_cursor
FETCH NEXT from deleted_query_cursor
into @AdHocQueryID
-- Check @@FETCH_STATUS to see if there are any more rows to fetch.
WHILE @@FETCH_STATUS = 0
begin
-- delete related table-value function
exec USP_ADHOCQUERY_DELETEIDSET @AdHocQueryID
-- for static queries, delete the related static table
exec USP_ADHOCQUERY_DELETESTATICTABLE @AdHocQueryID
FETCH NEXT from deleted_query_cursor into @AdHocQueryID
end
CLOSE deleted_query_cursor
DEALLOCATE deleted_query_cursor