Hay buenas respuestas en esta publicación. Agregando que el valor 'MS_Description' podría ser otra cosa. Por ejemplo, podemos usar 'SourceDescription' para obtener detalles sobre el origen de los datos, 'TableDescription' para la tabla y 'ColumnDescription' para cada columna en la tabla.
Ejemplo:
-- Create example table
create table testTablename(
id int,
name varchar(20),
registerNumber bigint
)
-- SourceDescription
EXEC sys.sp_addextendedproperty
@name=N'SourceDescription',
@value=N'Result of process x union y ' , -- Comment about the source this data.
@level0type=N'SCHEMA',
@level0name=N'dbo',
@level1type=N'TABLE',
@level1name=N'testTableName' -- Name of Table
-- TableDescription
EXEC sys.sp_addextendedproperty
@name=N'TableDescription',
@value=N'Table is used for send email to clients.' , -- Coment about the used of table
@level0type=N'SCHEMA',
@level0name=N'dbo',
@level1type=N'TABLE',
@level1name=N'testTableName'
-- ColumnDescription
EXECUTE sp_addextendedproperty
@name = 'ColumnDescription',
@value = 'Unique identification of employer. Its the registry of company too.',
@level0type = 'SCHEMA',
@level0name= N'dbo',
@level1type = N'TABLE',
@level1name = N'testTableName',
@level2type = N'COLUMN',
@level2name = N'registerNumber'
-- If necessary, you can delete the comment.
exec sp_dropextendedproperty
@name = 'ColumnDescription',
@level0type = 'SCHEMA',
@level0name= N'dbo',
@level1type = N'TABLE',
@level1name = N'testTableName',
@level2type = N'COLUMN',
@level2name = N'registerNumber'
-- Show you the table resume
select
tables.name tableName,
tables.create_date,
tables.modify_date,
tableDesc.value TableDescription,
sourceDesc.value SourceDescription
from
sys.tables
left join sys.extended_properties tableDesc on tables.object_id = tableDesc.major_id and tableDesc.name = 'TableDescription'
left join sys.extended_properties sourceDesc on tables.object_id = sourceDesc.major_id and sourceDesc.name = 'SourceDescription'
where
tableDesc.name in('TableDescription', 'SourceDescription', 'ColumnDescription')
order by tables.name
-- show you the columns resume
select
tables.name tableName,
columns.name columnName,
extended_properties.value
from
sys.tables
inner join sys.columns on tables.object_id = columns.object_id
left join sys.extended_properties on
tables.object_id = extended_properties.major_id
and columns.column_id = extended_properties.minor_id
and extended_properties.name in('MS_Description','ColumnDescription')
where
tables.name = 'testTableName'
Ver también [SQL Server administrar descripciones de las columnas por script] (https://stackoverflow.com/questions/17086651/sql-server-manage-column-descriptions-by-script) con práctico SP personalizado. – Vadzim