sql server 添加、查询 字段、表注释

环境:xp sp3,sql server2008

1、sqlserver用语句给表注释
EXECUTE sp_addextendedproperty N'MS_Description', N'表注释', N'user', N'dbo', N'table', N'', NULL, NULL

2、sqlserver用语句给表的“字段”注释
EXECUTE sp_addextendedproperty N'MS_Description', N'字段注释', N'user', N'dbo', N'table', N'表名', N'column', N'字段名'

3、查看sqlserver注释

SELECT
A.name AS table_name,
B.name AS column_name,
C.value AS column_description
FROM sys.tables A
INNER JOIN sys.columns B ON B.object_id = A.object_id
LEFT JOIN sys.extended_properties C ON C.major_id = B.object_id AND C.minor_id = B.column_id
WHERE A.name = '表名'

4、顺便加上sql server2000查看注释的语句

select so.name as table_name, sc.name as column_name, sc.xtype as data_type ,sp.value as remarks from sysobjects so left outer join syscolumns sc on so.id = sc.id left outer join sysproperties sp on sc.id = sp.id and sc.colid = sp.smallid where so.type = 'u' and so.name='表名' order by so.id, sc.colorder

上面的添加表和字段注释的语句在sql server2000 下也是可以使用的。

转自:http://begoodluck.blog.163.com/blog/static/20450728020141191412788/

你可能感兴趣的:(sql,sqlserver,MS,字段注释,字段注释)