-
Notifications
You must be signed in to change notification settings - Fork 23
/
DBLevelUserPermissions2.sql
62 lines (50 loc) · 1.34 KB
/
DBLevelUserPermissions2.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
USE MASTER
GO
BEGIN
DECLARE @databasename VARCHAR(30)
DECLARE cur CURSOR FOR
SELECT name
FROM sysdatabases
CREATE TABLE #result
(
dbname VARCHAR(120),
result VARCHAR(300)
)
OPEN cur
FETCH NEXT FROM cur INTO @databasename
WHILE( @@FETCH_STATUS = 0 )
BEGIN
CREATE TABLE #t
(
Owner VARCHAR(120),
Object VARCHAR(120),
Grantee VARCHAR(120),
Grantor VARCHAR(120),
ProtectType VARCHAR(120),
Action VARCHAR(120),
AColumn VARCHAR(120)
)
INSERT INTO #t
EXEC Sp_helprotect @username = NULL
INSERT INTO #result
SELECT @databasename,
ProtectType + ' ' + Action + ' on [' + Owner + '].[' + Object + ']' + CASE
WHEN (
Patindex('%All%', AColumn) = 0 )
AND
( AColumn <> '.' )
THEN
' (' + AColumn + ')' ELSE ''
END + ' to [' + Grantee + ']'
FROM #t
WHERE Grantee != 'public'
DROP TABLE #t
FETCH NEXT FROM cur INTO @databasename
END
SELECT *
FROM #result
ORDER BY 1
CLOSE cur
DEALLOCATE cur
DROP TABLE #result
END