MSSQL adds field description

  • 2020-05-07 20:34:46
  • OfStack

-- field add description
EXEC sp_addextendedproperty 'MS_Description', 'instructions to add ', 'user',' dbo ', 'table', table name, 'column', column name
-- delete field description
EXEC sp_dropextendedproperty 'MS_Description', 'user', dbo, 'table', table name, 'column', field name
-- view the field description

SELECT 
[Table Name] = i_s.TABLE_NAME, 
[Column Name] = i_s.COLUMN_NAME, 
[Description] = s.value 
FROM 
INFORMATION_SCHEMA.COLUMNS i_s 
LEFT OUTER JOIN 
sysproperties s 
ON 
s.id = OBJECT_ID(i_s.TABLE_SCHEMA+'.'+i_s.TABLE_NAME) 
AND s.smallid = i_s.ORDINAL_POSITION 
AND s.name = 'MS_Description' 
WHERE 
OBJECTPROPERTY(OBJECT_ID(i_s.TABLE_SCHEMA+'.'+i_s.TABLE_NAME), 'IsMsShipped')=0 
AND i_s.TABLE_NAME = 'jobs' 
ORDER BY 
i_s.TABLE_NAME, i_s.ORDINAL_POSITION

Related articles: