Error 313



Message text

A dirty read scan requires a unique index (unless the user forced a non-unique index or table scan). The optimizer could not find a unique index to use.


Isolation level 0 (zero) allows transactions to read uncommitted data (dirty reads). Since level 0 scans do not acquire locks, modifications by other processes can cause rows being scanned to move. When this occurs, Adaptive Server restarts the scan. To restart properly, the scan must use the same key used to find the modified row, and start again from the next key in the index; that is, the scan must be on a unique index. Error 313 occurs when a unique index does not exist during a dirty read scan.


To resolve the problem, create a unique index using one of these methods:

If your table has one or more IDENTITY columns, you can, for future indexes you create for this table, use the database option identity in nonunique index. When this option is set, any nonunique index created on a table with an IDENTITY column will automatically have the IDENTITY column included as the last key field of the index. This allows an otherwise nonunique index to be used for a cursor declared for update.

However, all indexes would then be considered unique by the optimizer since every index that is created would be unique and this could result in poor performance for some queries. Since the identity in nonunique index option does not affect existing indexes, only future indexes you create, the existing 313 error will not be resolved.

WARNING! Do not use the identity in nonunique index option unless you plan to test your queries.

To use the identity in nonunique index option, the table must already have an IDENTITY column, either from a create table statement or by setting the auto identity database option to true before creating the table.

The commands to set this option are:

1> use master
2> go

1> sp_dboption <database_name>,
2> "identity in nonunique index", true
3> go

1> use <database_name>
2> go

1> checkpoint
2> go

Where <database_name> is the name of the actual Adaptive Server.


Using forceindex with a clustered nonunique index uses key values to restart the scan at the first row that has key values.

To force Adaptive Server to use a nonunique index for your table scan, use forceindex. However, the restart will either be approximate or fail altogether if a row becomes invalidated. If the restart fails, your query will abort.

WARNING! Do not use forceindex with dirty reads.

Additional information

Refer to the Reference Manual: Commands for information about create index and alter table, and Reference Manual: Procedures for information about sp_dboption.

Versions in which this error is raised

All versions