-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRevokeAllObjects.sql
46 lines (40 loc) · 1.18 KB
/
RevokeAllObjects.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
USE [Certificate_Administration]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- ======================================================================
-- Author: John Merkel
-- Creation date: October 25, 2021
-- Description: Revokes all permissions/roles for all SourceObjects.
-- Requires: SA
-- ======================================================================
CREATE OR ALTER PROCEDURE [Permission].[RevokeAllObjects]
@DropRequests BIT
, @debug BIT = 1
AS
SET XACT_ABORT, NOCOUNT ON
BEGIN TRY
BEGIN TRANSACTION
DECLARE @SourceObjectID INT
DECLARE [src_object_cur] CURSOR STATIC LOCAL FOR
SELECT DISTINCT [SourceObjectID]
FROM [Permission].[SourceObject]
WHERE [SourceObjectID] IS NOT NULL
OPEN [src_object_cur]
WHILE 1 = 1
BEGIN
FETCH NEXT FROM [src_object_cur] INTO @SourceObjectID
IF @@FETCH_STATUS <> 0 BREAK
EXEC [Permission].[RevokeObjectByID] @SourceObjectID, @DropRequests, @debug
END
CLOSE [src_object_cur]
DEALLOCATE [src_object_cur]
COMMIT TRANSACTION
END TRY
BEGIN CATCH
IF @@TRANCOUNT > 0 ROLLBACK TRANSACTION
; THROW
END CATCH
GO