SQL Server edit, modify field description (note) sp_addextendedproperty

Source: Internet
Author: User

Grammar
Sp_addextendedproperty    [@name =] {' property_name '}    [, [@value =] {' Value '}         [, [@level0type =] {' L Evel0_object_type '}                     , [@level0name =] {' Level0_object_name '}                 [, [@level1type =] {' Level1_object_type '}
      , [@level1name =] {' Level1_object_name '}                         [, [@level2type =] {' Level2_object_type '}                                                     , [@level2name = ] {' Level2_object_name '}]]             
Notes

To specify extended properties, the objects in the SQL Server database are divided into three levels (0, 1, and 2). Level 0 is the highest level and is defined as an object that is contained in the database scope. Level 1 objects are included in the schema scope or user scope, and level 2 objects are contained in Level 1 objects. You can define extended properties for objects at any level in these levels.

References to objects in a level must be restricted with the name of a higher-level object that owns or contains them. For example, when you add an extended property to a table column (Level 2), you must also specify the table name (Level 1) that contains the column, and the schema that contains the table (level 0).

For a complete list of the objects and their valid levels 0, 1, and 2 types, see Using Extended Properties on database objects.

If all object types and names are empty, the property belongs to the current database itself.

Extended properties are not allowed for system objects, objects other than the scope of the user-defined database, or objects that are not listed as valid inputs in Arguments.

Schemas and users

In earlier versions of SQL Server, users owned database objects such as tables, views, and triggers. Therefore, extended attributes are allowed to be added to one of these objects and the user name is specified as a level 0 type. However, in SQL Server 2005, database objects are included in the schema. They are independent of the user who owns the schema.

In SQL Server 2005, we recommend that you do not specify USER as the level 0 type when applying extended properties to database objects, because this results in ambiguous name resolution. For example, assume that a user Mary has two schemas (Mary and MySchema), and both schemas contain a table named MyTable. If Mary adds an extended property to the table MyTable and specifies @level0type = N ' USER ', @level0name = Mary, then which table is not explicitly applied to the extended attribute. To maintain backward compatibility, SQL Server applies attributes to the tables contained by the schema named Mary. For more information about users and schemas, see User schema separation.

Parameters
[@name] = {' Property_name '}

The name of the property to add. The property_name data type is sysname and cannot be NULL. The name can also include a space or non-alphanumeric string, and a binary value.

[@value =] {' Value '}

The value to associate with the property. The data type of value is sql_variant, and the default value is NULL. Value cannot exceed 7,500 bytes in size.

[@level0type =] {' Level0_object_type '}

The type of the level 0 object. The Level0_object_type data type is varchar (128) and the default value is NULL.

Valid inputs include: ASSEMBLY, contract, EVENT NOTIFICATION, FILEGROUP, MESSAGE TYPE, PARTITION FUNCTION, PARTITION SCHEME, REMOTE Service BINDING, ROUTE, SCHEMA, service, USER, TRIGGER, TYPE, and NULL.

Important matters:
USER and type as Level 0 types will be removed in a future version of SQL Server. Avoid using these features in new development work, and consider modifying applications that currently use these features. Use SCHEMA instead of USER as Level 0 type. For type, use the SCHEMA as the level 0 type, using type as the Level 1 type.

[@level0name =] {' Level0_object_name '}

The name of the level 0 object type specified. The Level0_object_name data type is sysname and the default value is NULL.

[@level1type =] {' Level1_object_type '}

The type of the Level 1 object. The Level1_object_type data type is varchar (128) and the default value is NULL. Valid inputs include: AGGREGATE, DEFAULT, FUNCTION, LOGICAL FILE NAME, PROCEDURE, QUEUE, RULE, synonym, TABLE, TYPE, VIEW, XML SCHEMA COLLECTION and NULL.

[@level1name =] {' Level1_object_name '}

The name of the Level 1 object type specified. The Level1_object_name data type is sysname and the default value is NULL.

[@level2type =] {' Level2_object_type '}

The type of the Level 2 object. The Level2_object_type data type is varchar (128) and the default value is NULL. Valid inputs include: COLUMN, CONSTRAINT, EVENT NOTIFICATION, INDEX, PARAMETER, TRIGGER, and NULL.

[@level2name =] {' Level2_object_name '}

The name of the level 2 object type specified. The Level2_object_name data type is sysname and the default value is NULL.

Return code value

0 (Success) or 1 (failed)

execSys.sp_addextendedproperty@name =N'ms_description',@value =N'0: Cancel, 1: Arrived, 2: Not yet, 3: book default',@level0type =N'SCHEMA',@level0name =N'dbo',@level1type =N'TABLE',@level1name =N'Tab_passenger',@level2type =N'COLUMN',@level2name =N'passengerstate'--table and field Description Information Processing Example--Create a tableCreate TableTable (A1varchar(Ten), A2Char(2))--add descriptive information to a tableExecuteSp_addextendedproperty N'ms_description','Personnel Information Sheet'N'User'N'dbo'N'Table'N'Table',NULL,NULL--Add descriptive information for field A1ExecuteSp_addextendedproperty N'ms_description','name'N'User'N'dbo'N'Table'N'Table'N'column'N'A1'--Add descriptive information for field A2ExecuteSp_addextendedproperty N'ms_description','Sex'N'User'N'dbo'N'Table'N'Table'N'column'N'A2'--Update the Description property of the column A1 in the table:execSp_updateextendedproperty'ms_description','Field 1','User'Dbo'Table','Table','column', A1--Delete the Description property of the column A1 in the table:execSp_dropextendedproperty'ms_description','User'Dbo'Table','Table','column', A1--Delete TestDrop TableTable

SQL Server Edit, modify field description (note) Sp_addextendedproperty

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.