The requirement is to add remarks with statements, but the method we use is a very mature method sp_addextendedproperty that comes with it. Let’s go directly to the example to solve the current demand:
Add field description:
EXEC sys.sp_addextendedproperty @name = N'MS_Description',
@value = N'姓名',
@level0type = N'SCHEMA',
@level0name = N'dbo',
@level1type = N'TABLE',
@level1name = N'a', --修改的表名
@level2type = N'COLUMN',
@level2name = N'name'; --修改的字段
GO
result:
The specific introduction of sp_addextendedproperty is as follows:
The syntax is as follows:
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 '}
The name of the property to add. property_name is sysname and cannot be NULL. Names can also include spaces or non-alphanumeric strings and binary values.
[ @value= ] {' value '}
The value to associate with the property. Value sql_variant , default is NULL. The size of value cannot exceed 7,500 bytes.
[ @level0type= ] {' level0_object_type '}
Type of level 0 object. level0_object_type is varchar (128) , the default value is NULL.
有效输入包括:ASSEMBLY、CONTRACT、EVENT NOTIFICATION、FILEGROUP、MESSAGE TYPE、PARTITION FUNCTION、PARTITION SCHEME、REMOTE SERVICE BINDING、ROUTE、SCHEMA、SERVICE、USER、TRIGGER、TYPE、PLAN GUIDE 和 NULL。
[ @level0name= ] The name of the level 0 object type specified by {' level0_object_name '} . level0_object_name is sysname , the default value is NULL.
[ @level1type= ] {' level1_object_type '}
Type of level 1 object. level1_object_type is varchar (128) , the default value is NULL. Valid inputs include AGGREGATE, DEFAULT, FUNCTION, logical filename, PROCEDURE, QUEUE, RULE, SEQUENCE, SYNONYM, TABLE, TABLE_TYPE, TYPE, VIEW, XML SCHEMA COLLECTION, and NULL. [ @level1name= ] The name of the level 1 object type specified by
{ ' level1_object_name ' } . level1_object_name is sysname , the default value is NULL.
[ @level2type= ] {' level2_object_type '}
Type of level 2 object. level2_object_type is varchar (128) , the default value is NULL. Valid inputs include: COLUMN, CONSTRAINT, EVENT NOTIFICATION, INDEX, PARAMETER, TRIGGER, and NULL.
[ @level2name= ] The name of the level 2 object type specified by {' level2_object_name '} . level2_object_name is sysname , the default value is NULL.