Available with Standard or Advanced license.
You can execute SQL SELECT statements against versioned views to access versioned data.
Read from the Default version
You have two options when running SQL statements against the Default version: you can read the latest or read from a version state you specify.
Read the latest state of the Default version
Versioned views automatically access the current state of the Default version. If you execute SELECT statements against a versioned view, it will access the current state of Default at the time you execute the statement. If other users are committing edits to the Default version (thereby changing the state that the Default version references), your subsequent queries will see the latest state and their edits.
Read a specific version state
If you want to query a specific state of the Default version and don't want the state to change while you are querying, execute the version_util.set_current_version utility. This procedure validates the supplied version name and sets the corresponding database state internally. If you execute version_util.set_current_version for the Default version, queries you make against Default will always point to the state Default referenced when you executed the version_util.set_current_version utility.
Version_util.set_current_version can be executed directly from a SQL client. The syntax is as follows:
EXEC sde.version_util.set_current_version('<version_name>')
- Be sure there is a versioned view for the versioned feature class or table you want to access.
Beginning with ArcGIS 10.1, versioned views are created when you version data. If your data was versioned prior to 10.1, you can create a versioned view by right-clicking the dataset, pointing to Manage, and clicking Enable SQL Access.
- At an SQL prompt, execute the
version_util.set_current_version utility to set the version to Default.
EXEC sde.version_util.set_current_version('DEFAULT')
- Issue a SELECT statement against the versioned view to read versioned data from the geodatabase.
In this example, the versioned view is sightings_ev.
SELECT ID, SPECIES, REPORTER FROM SIGHTINGS_EV WHERE REPORTER = 'CHUCK';
Read a version other than Default
You can also execute the sde.version_util.set_current_version utility to query a version other than Default. This utility validates the version name you specify, and sets the corresponding version state internally. Queries you make against the version always point to the state the version referenced when you executed sde.version_util.set_current_version.
This utility can be called again to change to other versions as required and can be called each time the workspace is refreshed to return the current state of the versioned table to the calling application.
The following steps show you how to run version_util.set_current_version to query a specific version other than Default:
- Be sure there is a versioned view for the versioned feature class or table you want to access.
Beginning with ArcGIS 10.1, versioned views are created when you version data. If your data was versioned prior to 10.1, you can create a versioned view by right-clicking the dataset, pointing to Manage, and clicking Enable SQL Access.
- At an SQL prompt, execute the
version_util.set_current_version utility to set the version you
want to query.
In this example, FIELD_INSPECTIONS is set as the version to be queried in the master sde geodatabase. If you run this against a version in a user-schema geodatabase, the utility is prefaced with the geodatabase owner's name.
EXEC sde.version_util.set_current_version('FIELD_INSPECTIONS')
- Issue a SELECT statement against the versioned view to read versioned data from the geodatabase.
In this example, the versioned view is code_ev.
SELECT violationID,codenum,propowner,insp_date FROM code_ev WHERE zip = '99999';
If you need to return to querying the current state of the Default version, execute the set_default procedure.
CALL sde.version_util.set_default();