SQL Server添加字段注释表注释comments,Oracle与Sql Server添加注释语法区别

SQL Server添加字段注释,添加表注释comments

在SQL Server语法中,给表字段与表添加注释与Oracle语法有的很大的区别。

  • Oracle语法添加字段注释

语法

COMMENT on column 表.字段 is '字段注释';
COMMENT ON table 表 IS '表注释';

示例

--添加userTest表的userName字段注释为"用户姓名"
COMMENT on column userTest.userName is '用户姓名';
--添加userTest表的表注释为"用户信息表"
COMMENT ON table userTest IS '用户信息表';

--对于删除、更新注释语法一样,直接更改即可。
--删除userTest表的userName字段注释
COMMENT on column userTest.userName is '';
--删除userTest表的表注释
COMMENT ON table userTest IS '';
  • Sql Server语法添加字段注释

语法

--添加字段注释
execute sp_addextendedproperty 'MS_Description','填写你的字段注释','user','DB schema','table','填写表名','column','字段名';
--修改字段注释
execute sp_updateextendedproperty 'MS_Description','填写你的字段注释','user','DB schema','table','填写表名','column','字段名';
--删除字段注释
execute sp_dropextendedproperty 'MS_Description','user','DB schema','table','填写表名','column','字段名';

-- 添加表注释
execute sp_addextendedproperty 'MS_Description','填写你的表注释','user','DB schema','table','填写表名',null,null;
-- 修改表注释
execute sp_updateextendedproperty 'MS_Description','填写你的表注释','user','DB schema','table','填写表名',null,null;
-- 删除表注释
execute sp_dropextendedproperty 'MS_Description','user','DB schema','table','填写表名',null,null;

示例

--字段注释处理
--添加dbo下的userTest表的userName字段注释为"用户名"
execute sp_addextendedproperty 'MS_Description','用户名','user','dbo','table','userTest','column','userName';
--修改dbo下的userTest表的userName字段注释为"xxx"
execute sp_updateextendedproperty 'MS_Description','xxx','user','dbo','table','userTest','column','userName';
--删除dbo下的userTest表的userName字段注释
execute sp_dropextendedproperty 'MS_Description','user','dbo','table','userTest','column','userName';

---表注释处理
-- 添加dbo下的userTest表注释为"用户信息测试表"
execute sp_addextendedproperty 'MS_Description','用户信息测试表','user','dbo','table','userTest',null,null;
-- 修改dbo下的userTest表注释为"xxxxx"
execute sp_updateextendedproperty 'MS_Description','xxxxx','user','dbo','table','userTest',null,null;
-- 删除dbo下的userTest表注释
execute sp_dropextendedproperty 'MS_Description','user','dbo','table','userTest',null,null;