获取库中的所有字段的描述/获取某个表中所有字段方法

--获取库中的所有字段的描述
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

--获取某个表中所有字段方法
1)
 SELECT name
    FROM syscolumns
    WHERE [id] = OBJECT_ID('tablename')
2)
SELECT column_name
    FROM INFORMATION_SCHEMA.COLUMNS
    WHERE table_name='tablename'

3)
EXEC sp_columns @table_name='tablename'

 

posted @ 2011-04-13 14:19  笑萧亦然  阅读(192)  评论(0编辑  收藏  举报