Editing versioned data in SQL Server using multiversioned views and SQL

You can edit versioned data in a geodatabase by editing a multiversioned view created on the data.

There are several stored procedures installed with ArcSDE that help you work with multiversioned views. These components and their descriptions are as follows:

Stored procedure

Purpose

Syntax and description

create_version

Create a new geodatabase version.

Always edit your own, separate version; multiple editors cannot edit the same version using multiversioned views.

EXEC {dbo | sde}.create_version '<parent_version>', '<child_version>', <name_rule>, <access>, '<description>'

  • <parent_version>: The version from which your version is created
  • <child_version>: The name of the version you are creating
  • <name_rule>: Indicates whether the name specified for the version should be taken as given (2) or a unique name should be created when a duplicate name is specified (1)
  • <access>: The permission level for the version: either 0 for private (only the version owner can access it), 1 for public (all users can access it), or 2 for protected (the version owner has read/write permissions on the version, but everyone else has read-only permission)
  • <description>: A text description of the child version

set_current_version

Set which geodatabase version you will access.

EXEC {dbo | sde}.set_current_version '<version_name>'

  • <version_name>: The version you want to edit

edit_version

Start and end an edit session.

EXEC {dbo | sde}.edit_version '<version_name>',{1 | 2}

Specify 1 to start the edit session. Specify 2 to end it.

delete_version

Delete a geodatabase version.

EXEC {dbo | sde}.delete_version '<version_name>'

When you edit versioned tables through multiversioned views, changes are made to the delta tables, and row ID (object ID) values for new records are automatically generated. However, unlike editing versioned data in an ArcGIS edit session, no internal version reconciliation is done with these edits.

Additionally, an exclusive lock is placed on the state that the version references when you start an edit session on a multiversioned view. Therefore, it is strongly recommended that multiversioned views not be used to edit the DEFAULT version or any version that may be subject to simultaneous editing or reconciliation by other users because conflicts will not be detected and locks will block other users. Instead, create your own version specifically for your multiversioned view edit session.

CautionCaution:
  • Version management operations, such as reconciling, resolving conflicts, and posting, must be done using the ArcGIS software. Improper version management can lead to geodatabase corruption when working with views.
  • Never use database management system (DBMS) tools to update any row ID (object ID) field maintained by ArcSDE in the database. These object ID fields are allocated and managed by the geodatabase and, therefore, should not be altered using SQL.
  • Never edit the DEFAULT version of the geodatabase using SQL. Starting an edit session on a version obtains an exclusive lock on the state that the version references. If you lock the DEFAULT version, you prevent ArcGIS users from connecting to the geodatabase.

The following steps guide you through creating a multiversioned view, creating a version in which to perform edits, setting the version to edit, starting an edit session, performing some edits through the multiversioned view, stopping the edit session, committing your edits to the database, and deleting the version created for the edits. In the examples, the multiversioned view created to perform the edits on the table is code_mv, and the version created and used for editing is mvedits.

TipTip:

Remember that the dataset you edit through a multiversioned view must already have been registered as versioned.

Steps:
  1. At an MS-DOS command prompt, execute the sdetable utility to create a multiversioned view.
    sdetable –o create_mv_view –T code_mv –t code_enf 
    –i sde:sqlserver:myserver\ssinst –D code –u sarja –p not4u
  2. You can use the create_version procedure to create a version in which to perform your edits.
    EXEC sde.create_version 'sde.DEFAULT', 'version2', 1, 2, 'version for my mv edits'
  3. Open a Transact SQL query window and execute the set_current_version stored procedure.
    EXEC sde.set_current_version 'version2'
    NoteNote:

    If you do not set the current version, each time you query you will see the latest state of the DEFAULT version. If you set the current version, the state is cached and your view of the version you specified remains static.

  4. Start an edit session by executing the edit_version stored procedure and specifying 1.
    EXEC sde.edit_version 'version2', 1

    The 1 indicates an edit session should be started.

  5. Perform the first edit to the multiversioned view using SQL.

    In this example, an existing record is updated.

    UPDATE code_mv 
    SET propowner = 'C. Industry' 
    WHERE vid = 2233
  6. Perform the next edit to the multiversioned view using SQL.

    In this example, a record is inserted to the table.

    INSERT INTO code_mv 
    (codenum, propowner) 
    VALUES (456, 'Anjo Badsu')
    TipTip:

    In the INSERT statement, no object ID value is specified; the multiversioned view automatically gets the next available object ID and inserts it for the row.

    Although it is possible to version a table that has only been registered with ArcSDE and has a user-maintained object ID column, this is not recommended. If you do this anyway, though, you must provide an object ID with the INSERT statements; the multiversioned view cannot generate a value for you.

  7. Stop the edit session by executing the edit_version stored procedure, but specify 2.
    EXEC sde.edit_version 'version2', 2

    The 2 indicates the edit session should be ended.

  8. When all editing is done, reconcile and post edits through ArcGIS Desktop, then delete the geodatabase version you created in step 2. Or if you decide you do not want the changes, you can delete the version you created in step 2 without reconciling and posting the edits.
    EXEC sde.delete_version 'version2'

Related Topics


11/18/2013