HOW TO

Use SQL to insert a value into a Global ID or GUID column in an Enterprise geodatabase, versioned views in SQL Server

Last Published: November 11, 2020

Summary

Instructions provided describe how to insert a value into a Global ID or Globally Unique Identifier (GUID) column in an Enterprise geodatabase, versioned views using Structured Query Language (SQL) in Microsoft SQL Server.

Procedure

Global ID and GUID data types store registry style strings consisting of 36 characters enclosed in curly brackets. These strings uniquely identify a feature or table row within a geodatabase and across geodatabases. This is how features are tracked in one-way and two-way geodatabase replication and used in relationships or in any application requiring globally unique identifiers.

In a relationship, if a Global ID field is the origin key, a GUID field must be the destination key. Add Global IDs to a feature class in ArcCatalog by right-clicking the feature class and clicking Add Global IDs. The geodatabase maintains these values automatically. Create the GUID field in ArcCatalog, and maintain its values.

When inserting a row into a versioned view with a Global ID column using SQL, provide a unique GUID value for the Global ID column. As described in the procedure below:

Note:
For more information related to Global IDs, GUIDs, and Geodatabase Replication, refer to the ArcGIS Desktop Help in the Related Information section.
Examples provided are specific to Microsoft SQL Server; steps are similar for other supported databases.
  1. When registering a feature class as versioned, the versioned view is automatically created by the software. Assuming that the feature class ‘parcels’ has a global ID field and is registered as versioned, identify the versioned view by viewing the feature class properties. The Versioned View Name is listed under the Source tab, as shown in the image below.
image of feature class properties
  1. Open a SQL Server Query Analyzer and login as a user who has permission to edit the 'parcels' feature class.
  2. Create a new version:
exec sde.create_version N'sde.default', N'parcels_42',2, 2, 'Parcels Version' -- parcels_42 is the name of the version to create and 'Parcels Version' is the description.
  1. Set the current version for editing:
exec sde.set_current_version 'parcels_42' 
  1. Start the edit session:
exec sde.edit_version 'parcels_42', 1
Note:
newid() is a built-in function in SQL Server to create new unique GUID.
  1. Insert a record.
insert into sde.parcels_evw (parcel_id,Globalid) values (87701578, newid())
  1. Close the edit session.
exec sde.edit_version 'parcels_42', 2

Article ID:000009543

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options

Related Information

Discover more on this topic