ms-sql 给表列添加注释

需求:

    在创建数据库是对相应的数据库、表、字段给出注释。

 

解决方案:

    首先,要明确一点的是注释存在sysproperties表中而不是跟创建的表捆绑到一起的(我的理解)。

一、使用SQL Server窗口创建表是会有注释窗口;

二、使用SQL语句的comment语句,该语句放置在create table()后面,如:

      comment on table table_name is 'table_mark'

      comment on column table_name."Column" is 'column_mark'

三、调用系统存储过程sp_addextendedproperty来添加注释,如:

EXECUTE sp_addextendedproperty N'MS_Description',N'雇员信息',N'user',N'dbo',N'table',N'Employee',NULL,NULL

EXECUTE sp_addextendedproperty N'MS_Description',N'主键ID,自动增加',N'user',N'dbo',N'table',N'Employee',N'column',N'EmployeeID'

或者

EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'角色ID' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'CharData', @level2type=N'COLUMN',@level2name=N'charid'
GO

posted @ 2014-04-28 10:12  kedarui  阅读(790)  评论(0编辑  收藏  举报