-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path06.SQLServer2019.SqlDataClassification.sql
More file actions
70 lines (58 loc) · 1.84 KB
/
06.SQLServer2019.SqlDataClassification.sql
File metadata and controls
70 lines (58 loc) · 1.84 KB
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
63
64
65
66
67
68
69
70
USE dbTest
GO
CREATE TABLE people
(
idRow int,
name varchar(50),
surname varchar(50),
ssn varchar(15),
emailAddress varchar(50),
hashedPassword varchar(20)
)
GO
insert people values (1, 'aaa', 'bbb', '123-xxx-123', 'aaa@bbb.com', 'x0138fakag')
GO
/* view data*/
select * from people
go
/*
The Classify data features adds extended properties
to the columns to specify the label and the information type.
*/
/* Data Classification, in SSMS: right click on db --> Tasks --> Data Discovery and Classification --> Classify Data */
/* recommendations --> click to view --> select checkbox */
/* accept selected recommendations --> save */
/* all the columns in a database where we defined the data classification */
SELECT
Schema_name(objects.schema_id) AS schema_name,
objects.NAME AS table_name,
columns.NAME AS column_name,
ISNULL(EP.information_type_name,'') AS information_type_name,
ISNULL(EP.sensitivity_label_name,'') AS sensitivity_label_name
FROM
(
SELECT ISNULL(EC1.major_id,EC2.major_id) AS major_id,
ISNULL(EC1.minor_id,EC2.minor_id) AS minor_id,
EC1.information_type_name,
EC2.sensitivity_label_name
FROM
(
SELECT major_id, minor_id,
NULLIF(value,'') AS information_type_name
FROM sys.extended_properties
WHERE NAME = 'sys_information_type_name'
) EC1
FULL OUTER JOIN
(
SELECT major_id, minor_id,
NULLIF(value,'') AS sensitivity_label_name
FROM sys.extended_properties
WHERE NAME = 'sys_sensitivity_label_name') EC2
ON ( EC2.major_id = EC1.major_id AND EC2.minor_id = EC1.minor_id )
) EP
JOIN sys.objects objects ON EP.major_id = objects.object_id
JOIN sys.columns columns ON ( EP.major_id = columns.object_id AND EP.minor_id = columns.column_id )
GO
/* drop objects */
drop table people
go