SQL Server 字段和对应的说明操作(SQL Server 2005 +)

添加说明

EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'【说明文字】' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'【表名】', @level2type=N'COLUMN',@level2name=N'【字段】'

查询 

SELECT  
    [Table Name] = OBJECT_NAME(c.object_id), 
    [Column Name] = c.name, 
    [Description] = ex.value  
FROM  
    sys.columns c  
LEFT OUTER JOIN  
    sys.extended_properties ex  
ON  
    ex.major_id = c.object_id 
    AND ex.minor_id = c.column_id  
    AND ex.name = 'MS_Description'  
WHERE  
    OBJECTPROPERTY(c.object_id, 'IsMsShipped')=0  
    -- AND OBJECT_NAME(c.object_id) = 'your_table' 
ORDER  
    BY OBJECT_NAME(c.object_id), c.column_id

 

posted @ 2018-05-24 18:20  游子善心  阅读(6)  评论(0编辑  收藏  举报  来源