Created
January 29, 2020 00:07
-
-
Save xavierzwirtz/dc6a81ec2759979563995b77448e150b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SET ANSI_NULLS ON | |
GO | |
SET QUOTED_IDENTIFIER ON | |
GO | |
CREATE PROCEDURE [dbo].[bd_purge_audit] | |
AS | |
DECLARE @SQL varchar(max)='' | |
select @SQL = @SQL + ' | |
SET NOCOUNT ON; | |
DECLARE @r INT; | |
SET @r = 1; | |
WHILE @r > 0 | |
BEGIN | |
BEGIN TRANSACTION; | |
DELETE TOP (100000) | |
dbo.' + table_name + ' | |
WHERE SyncFlag = ''true''; | |
SET @r = @@ROWCOUNT; | |
COMMIT TRANSACTION; | |
END;' | |
from INFORMATION_SCHEMA.TABLES | |
where table_name like 'bdtriggeraudit%' | |
select @sql | |
EXEC (@SQL) | |
GO | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment