forked from PureStorage-OpenConnect/sqlserver-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Detect encryption and or compression.sql
51 lines (36 loc) · 1.89 KB
/
Detect encryption and or compression.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
-- Show any databases that might be using TDE
SELECT d.name FROM sys.databases d
WHERE d.is_encrypted = 1;
-- Show if any databases have any partitions with PAGE/ROW/ColumnStore compression
EXECUTE sys.sp_MSforeachdb N'USE ?; SELECT DISTINCT DB_NAME() + ''.'' + SCHEMA_NAME(o.schema_id) + ''.'' + OBJECT_NAME(p.object_id) As TableName, p.data_compression_desc As TypeOfCompression
FROM sys.partitions p
JOIN sys.objects o ON p.object_id = o.object_id
WHERE p.data_compression_desc <> ''NONE''
AND o.is_ms_shipped = 0'
-- Note: sp_MSforeachdb has some issues running against databases with "exotic" characters.
-- Use the code below to run on individual databases that might fit that criteria :)
/*
USE <myDatabaseName>;
SELECT DISTINCT DB_NAME() + ''.'' + SCHEMA_NAME(o.schema_id) + ''.'' + OBJECT_NAME(p.object_id) As TableName, p.data_compression_desc As TypeOfCompression
FROM sys.partitions p
JOIN sys.objects o ON p.object_id = o.object_id
WHERE p.data_compression_desc <> ''NONE''
AND o.is_ms_shipped = 0
*/
-- Potential high entropy columns (may or may not be encryption)
EXECUTE sys.sp_MSforeachdb N'USE ?; SELECT DISTINCT DB_NAME() + ''.'' + SCHEMA_NAME(o.schema_id) + ''.'' + OBJECT_NAME(c.object_id) + ''::'' + c.name
FROM sys.columns c
JOIN sys.types t ON c.system_type_id = t.system_type_id
JOIN sys.objects o ON c.object_id = o.object_id
WHERE t.name IN (''binary'', ''varbinary'')
AND o.is_ms_shipped = 0'
-- Same as above, use the manual query if you have databases with exotic names
/*
USE <MyDatabaseName>;
SELECT DISTINCT DB_NAME() + ''.'' + SCHEMA_NAME(o.schema_id) + ''.'' + OBJECT_NAME(c.object_id) + ''::'' + c.name
FROM sys.columns c
JOIN sys.types t ON c.system_type_id = t.system_type_id
JOIN sys.objects o ON c.object_id = o.object_id
WHERE t.name IN (''binary'', ''varbinary'')
AND o.is_ms_shipped = 0';
*/