Skip to content

Latest commit

 

History

History
46 lines (32 loc) · 3.84 KB

using-the-sql-identity-and-sql-guid-annotations.md

File metadata and controls

46 lines (32 loc) · 3.84 KB
title description author ms.author ms.date ms.service ms.subservice ms.topic monikerRange
Using the sql:identity and sql:guid Annotations
Learn how to use the sql:identity and sql:guid annotations in an XSD schema to define the behavior of an XML updategram.
MikeRayMSFT
mikeray
03/16/2017
sql
xml
reference
=azuresqldb-current||>=sql-server-2016||>=sql-server-linux-2017||=azuresqldb-mi-current

Using the sql:identity and sql:guid Annotations

[!INCLUDE 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 [!INCLUDEmsCoName] [!INCLUDEssNoVersion]. 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 [!INCLUDEssNoVersion] 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 [!INCLUDEssNoVersion]-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 [!INCLUDEssNoVersion] 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 [!INCLUDEssNoVersion] 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 [!INCLUDEssNoVersion] 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.