From 8eb545a37c7d63ca545f521af98549cdec43405e Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Thu, 27 Oct 2016 18:14:21 -0400 Subject: [PATCH] delete non-folders and then folders to avoid FK constraint issues when batch deleting --- src/Sql/dbo/Stored Procedures/User_DeleteById.sql | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Sql/dbo/Stored Procedures/User_DeleteById.sql b/src/Sql/dbo/Stored Procedures/User_DeleteById.sql index d3e83f7fa1..5176bde68a 100644 --- a/src/Sql/dbo/Stored Procedures/User_DeleteById.sql +++ b/src/Sql/dbo/Stored Procedures/User_DeleteById.sql @@ -3,10 +3,10 @@ AS BEGIN SET NOCOUNT ON + DECLARE @BatchSize INT = 100 BEGIN TRANSACTION User_DeleteById - DECLARE @BatchSize INT = 100 WHILE @BatchSize > 0 BEGIN DELETE TOP(@BatchSize) @@ -14,10 +14,18 @@ BEGIN [dbo].[Cipher] WHERE [UserId] = @Id + AND [Type] > 0 SET @BatchSize = @@ROWCOUNT END + DELETE + FROM + [dbo].[Cipher] + WHERE + [UserId] = @Id + AND [Type] = 0 + DELETE FROM [dbo].[Device]