SQL SERVER添加表注释、字段注释

SQL SERVER添加表注释、字段注释

在这里插入代码片
-- 添加表注释
execute sp_addextendedproperty 'MS_Description', '表备注内容', 'SCHEMA', 'dbo','table', '表名',NULL,NULL;
-- 修改表注释
execute sp_updateextendedproperty 'MS_Description','表备注内容','user','dbo','table','表名',NULL,NULL;
-- 添加字段注释
execute sp_addextendedproperty 'MS_Description','字段备注内容','user','dbo','table','字段表名','column','字段名';
-- 修改字段注释
execute sp_updateextendedproperty 'MS_Description','字段备注内容','user','dbo','table','字段表名','column','字段名';
-- 添加表名注释相当于添加字段,所以后面二个为NULL
-- 查找SQLSERVER的表
SELECT * FROM SYS.TABLES;
-- 查找添加的注释 
SELECT * FROM SYS.EXTENDED_PROPERTIES;
-- SYS.EXTENDED_PROPERTIES.MINOR_ID = 0  表示表名的注释
SELECT * FROM SYS.EXTENDED_PROPERTIES T WHERE T.MINOR_ID=0;
-- 查询表名对应的注释
SELECT CAST(T.NAME AS VARCHAR)   AS TABLE_NAME,
               CAST(T1.VALUE AS VARCHAR) AS TABLE_DESCRIPTION
        FROM SYS.TABLES T
                 LEFT JOIN SYS.EXTENDED_PROPERTIES T1 ON T.OBJECT_ID = T1.MAJOR_ID
            AND T1.MINOR_ID = 0
        ORDER BY T.NAME

SQL SERVER添加表注释、字段注释_第1张图片

你可能感兴趣的:(SQL,sql,sqlserver,数据库)