在SQL语句中通过系统存储过sp_addextendedproperty可为表字段添加上动态的说明(备注)下面是SQL SERVER帮助文档中对sp_addextendedproperty存储过程的描述
语法
sp_addextendedproperty
[ @name = ] { 'property_name' }
[ , [ @value = ] { 'value' }
[ , [ @level0type = ] { 'level0_object_type' }
, [ @level0name = ] { 'level0_object_name' }
[ , [ @level1type = ] { 'level1_object_type' }
, [ @level1name = ] { 'level1_object_name' }
[ , [ @level2type = ] { 'level2_object_type' }
, [ @level2name = ] { 'level2_object_name' }
]
]
]
]
参数
[ @name = ] { 'property_name' }
要添加的属性名称。property_name 的数据类型为 sysname,它不能是 NULL。名称可能还包括空白或非字母数字字符串和二进制值。
[ @value = ] { 'value' }
将要与属性相关联的值。value 的数据类型为 sql_variant,带有默认设置 NULL。value 的大小不能超过 7,500 字节;否则 SQL Server 会产生错误。
[ @level0type = ] { 'level0_object_type' }
用户或用户定义类型。level0_object_type 的数据类型为 varchar(128),其默认值为 NULL。有效的输入是 USER、TYPE 和 NULL。
[ @level0name = ] { 'level0_object_name' }
指定的 0 级对象类型的名称。level0_object_name 的数据类型为 sysname,其默认值为 NULL。
[ @level1type = ] { 'level1_object_type' }
1 级对象的类型。level1_object_type 的数据类型为 varchar(128),其默认值为 NULL。有效的输入是 TABLE、VIEW、PROCEDURE、FUNCTION、DEFAULT、RULE 和 NULL。
[ @level1name = ] { 'level1_object_name' }
指定的 1 级对象类型的名称。level1_object_name 的数据类型为 sysname,其默认值为 NULL。
[ @level2type = ] { 'level2_object_type' }
2 级对象的类型。level2_object_type 的数据类型为 varchar(128),其默认值为 NULL。有效的输入是 COLUMN、PARAMETER、INDEX、CONSTRAINT、TRIGGER 和 NULL。
[ @level2name = ] { 'level2_object_name' }
指定的 2 级对象类型的名称。level2_object_name 的数据类型为 sysname,其默认值为 NULL。
返回代码值
0(成功)或 1(失败)
use [jipiaojiekou1]
DROP TABLE modifiedPolicy
CREATE TABLE modifiedPolicy
(
[ID] INT ,
[airlineCode] varchar(50) ,
[flightCourse] varchar(50),
[commision] varchar(50)
)
下面是我在使用过程中对表modifiedPolicy的字段ID通过sp_addextendedproperty存储过程加的说明
EXEC sp_addextendedproperty N'MS_Description', N'政策ID', 'USER', N'dbo', 'TABLE', N'modifiedPolicy', 'COLUMN', N'ID'
EXEC sp_addextendedproperty N'MS_Description', N'政策ID', 'USER', N'dbo', 'TABLE', N'modifiedPolicy', 'COLUMN', N'ID'
也可以用
EXEC sp_addextendedproperty
@name = N'MS_Description', @value = 'Postal code is a required column.',
@level0type = N'Schema', @level0name = dbo,
@level1type = N'Table', @level1name = modifiedPolicy,
@level2type = N'Column', @level2name = ID;
GO