How to specify the description for columns when creating a table using SQL statements. It mainly uses the sp_addextendedproperty stored procedure.
Syntax
|
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' } ] ] ] ] |
-- Create a table
Create Table (A1 varchar (10), A2 char (2 ))
-- Add description information for the table
Execute sp_addextendedproperty n 'Ms _ description', 'personnel info table ', N 'user', N 'dbo', N 'table', N 'table', null, null
-- Add description information for field A1
Execute sp_addextendedproperty n 'Ms _ description', 'name', N 'user', N 'dbo', N 'table', N 'table', N 'column ', N 'a1'
-- Add description information for field A2
Execute sp_addextendedproperty n 'Ms _ description', 'gender', N 'user', N 'dbo', N 'table', N 'table', N 'column ', N 'a2'
-- Update the description attribute of column A1 in the table:
Exec sp_updateextendedproperty 'Ms _ description', 'field 1', 'user', DBO, 'table', 'table', 'column', A1
-- Delete the description attribute of column A1 in the table:
Exec sp_dropextendedproperty 'Ms _ description', 'user', DBO, 'table', 'table', 'column', A1
-- Delete test
Drop table