Επεξεργασία

Κοινή χρήση μέσω


Using the sql:identity and sql:guid Annotations

Applies to: SQL Server Azure SQL Database

You can specify the sql:identity and sql:guid annotations in an XSD schema on any node that maps to a database column in Microsoft SQL Server. Whereas the updategram format supports the updg:at-identity and updg:guid attributes, the DiffGram format does not. The updg:at-identity attribute defines the behavior in updating an IDENTITY-type column. The updg:guid attribute allows you to obtain a GUID value from SQL Server and use it in the updategram. For more information and working samples, see Inserting Data Using XML Updategrams (SQLXML 4.0).

The sql:identity and sql:guid annotations extend this functionality to DiffGrams.

When you execute a DiffGram, it is first converted to an updategram, and then the updategram is executed. By specifying the sql:identity and sql:guid annotations in the XSD schema, you are in fact defining the behavior of an updategram. Therefore, all the annotations are described in the context of an updategram. The annotations can be used both for DiffGrams and updategrams; however, updategrams already provide a more powerful way of handling identity and GUID values.

The sql:identity and sql:guid annotations can be defined on a complex content element.

sql:identity Annotation

You can specify the sql:identity annotation in the XSD schema on any node that maps to an IDENTITY-type database column. The value specified for this annotation defines how the IDENTITY-type column is updated (either by using the value provided in the updategram to modify the column or by ignoring the value, in which case a SQL Server-generated value is used for this column).

The sql:identity annotation can be assigned two values:

ignore
Directs the updategram to ignore any value that is provided in the updategram for that column and to rely on SQL Server to generate the identity value.

useValue
Directs the updategram to use the value that is provided in the updategram to update the IDENTITY-type column. An updategram does not check whether the column is an identity value or not.

If the updategram specifies a value for the IDENTITY-type column, the sql:identity="useValue" must be specified in the schema.

sql:guid Annotation

An updategram can have SQL Server generate a GUID value and then use this value in the updategram. In the context of DiffGrams, you can use the sql:guid annotation to specify whether to use a GUID value that is generated by SQL Server or use the value that is provided in the updategram for that column.

The sql:guid annotation can be assigned two values:

generate
Specifies that the GUID generated by SQL Server be used for that column in the update operation.

useValue
Specifies that the value specified in the updategram be used for the column. This is the default value.