English

How To: Use SQL to insert a value into a Global ID or GUID column in ArcSDE multiversion views in SQL Server

Summary

Instructions provided describe how to insert a value into a Global ID or Globally Unique Identifier (GUID) column in an ArcSDE multiversion view using Structured Query Language (SQL) for 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 ArcCatalog 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 multiversion 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 installed with ArcGIS Desktop or the link available in Related Information.

Examples provided are specific to SQL Server; steps are similar for other supported databases.

  1. Assuming that the feature class ‘parcels’ has a global ID field and is registered as versioned:

    Open a Windows command prompt and create the multiversion view using the ArcSDE sdetable command:

    Code:

    sdetable -o create_mv_view -T parcels_mv -t parcels -i 5176 -u user1 -p ***** -D <DataBase_Name> -s <Machine_name>


  2. Open an SQL Server Query Analyzer and login as a user who has permission to edit the 'parcels' feature class.
  3. Create a new version:

    Code:

    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.


  4. Set the current version for editing:

    Code:

    exec sde.set_current_version 'parcels_42'

  5. Start the edit session:

    Code:

    exec sde.edit_version 'parcels_42', 1


  6. Insert a record:

    Code:

    insert into sde.parcels_mv (parcel_id,Globalid) values (87701578, newid())


    Note:
    newid() is a built-in function in SQL server to create new unique GUID.


  7. Close the edit session:

    Code:

    exec sde.edit_version 'parcels_42', 2

Related Information