I am building a data dictionary and trying to get some info from the extended properties.
I have a script to add extended properties (working as expected).
EXEC sys.sp_addextendedproperty
@name=N'MS_Description',
@value=N'This column stores the bla bla bla.' ,
@level0type=N'SCHEMA',
@level0name=N'dbo', --Schema Name
@level1type=N'TABLE',
@level1name=N'my_super_crazy_table',--Table Name
@level2type=N'COLUMN',
@level2name=N'my_super_crazy_column'--Column Name
GO
Now I want to ideally be able to see when these are created/updated (bonus if I can see what user -- suser_sname())
My final query for the data dictionary is below:
SELECT tbl.name as [table_name],
clmns.name as [column_name],
exprop.value as [column_description]
-- exprop.*
FROM sys.tables AS tbl
INNER JOIN sys.all_columns AS clmns ON clmns.object_id=tbl.object_id
LEFT OUTER JOIN sys.extended_properties exprop ON exprop.major_id = clmns.object_id AND exprop.minor_id = clmns.column_id
WHERE (tbl.name IN ('my_super_crazy_table') and exprop.class = 1)
Output:
table_name | column_name | column_description
my_super_crazy_table|my_super_crazy_column|This column stores the bla bla bla.
Is there any other sys table that could give me the information I'm looking for?
Thanks
SQL Server doesn't currently store any information about when extended properties are added or updated, or by who.
There's quite a bit more logic that you'd probably eventually want to implement. Here's my current best script for it.
https://www.csvreader.com/posts/data_dictionary.sql