I'm using the SSMS tool Data Discovery and Classification.
The tool automatically search for columns name like %address%
, %name%
, %surname%
, %e-mail%
, %tax%
, %zip%
, etc...
and nicely suggests you what it might be a sensible data.
The fact is that outside from Anglo-Saxon societies the column name is not in English but it can be in French, Spanish, Italian, etc..
So I found a query that could help me out list sensible data based on my language:
SELECT schema_name(tab.schema_id) AS schema_name
,tab.name AS table_name
,col.name AS column_name
,t.name AS data_type
,NULL as Data_Preview
FROM sys.tables AS tab
INNER JOIN sys.columns AS col ON tab.object_id = col.object_id
LEFT JOIN sys.types AS t ON col.user_type_id = t.user_type_id
ORDER BY schema_name
,table_name
,column_id;
Very nice.
But it would be better if I could add a last column called Content
that PIVOT
the content of each column and SELECT TOP 5
of each one and nicely print it in the last column.
Can you help me archive that?
That would be a DYO Data Discovery and Classification.
EDIT: I might have expressed myself badly.
I'm running mz query against AdventureWorks2019:
schema_name | table_name | column_name | data_type | Data_Preview |
---|---|---|---|---|
Person | Address | AddressID | int | NULL |
Person | Address | AddressLine1 | nvarchar | NULL |
Person | Address | AddressLine2 | nvarchar | NULL |
Person | Address | City | nvarchar | NULL |
Person | Address | StateProvinceID | int | NULL |
Person | Address | PostalCode | nvarchar | NULL |
I want to PIVOT
the content of each column (let's say the TOP 5
) tho the last column
schema_name | table_name | column_name | data_type | Data_Preview |
---|---|---|---|---|
Person | Address | AddressID | int | 1,2,3,4,5 |
Person | Address | AddressLine1 | nvarchar | 1970 Napa Ct.,9833 Mt. Dias Blv.,7484 Roundtree Drive,9539 Glenside Dr,1226 Shoe St. |
Person | Address | AddressLine2 | nvarchar | NULL,NULL,NULL,NULL,NULL |
Person | Address | City | nvarchar | Bothell,Bothell,Bothell,Bothell,Bothell |
Person | Address | StateProvinceID | int | 79,79,79,79,79 |
Person | Address | PostalCode | nvarchar | 98011,98011,98011,98011,98011 |
Each data can be separated by a coma or whatever. The result is that I want to have a preview of the data that is actually in the column:
This guys apparently arrived to archive that:
- https://learn.microsoft.com/en-us/answers/questions/285445/how-to-get-column-values-in-one-comma-separated-va.html
- Pivot and comma Separated value
- https://www.mikekale.com/rows-to-comma-separated-lists-in-sql-server/
Thank you