Sets option values for user-defined indexes.
Note Microsoft® SQL Server™ automatically makes choices of page-, row-, or table-level locking. It is not necessary to set these options manually. sp_indexoption is provided for expert users who know with certainty that a particular type of lock is always appropriate.
sp_indexoption [@IndexNamePattern =] 'index_name'
[,[@OptionName =] 'option_name']
[,[@OptionValue =] 'value']
[@OptionName =] 'option_name'
Is an index option name. option_name is varchar(35), with a default of NULL, which lists all available table options and the corresponding default values assigned to new tables (0 = FALSE or off, 1 = TRUE or on). option_name can have these values.
Value | Description |
---|---|
AllowRowLocks | When FALSE, row locks are not used. Access to the specified indexes is obtained using page- and table-level locks. |
AllowPageLocks | When FALSE, page locks are not used. Access to the specified indexes is obtained using row- and table-level locks. |
[@OptionValue =] 'value'
Specifies whether the option_name setting is TRUE (on) or FALSE (off). value is varchar(12), with a default of NULL, which lists the current settings for all matching tables.
0 (success) or greater than 0 (failure)
Column name | Data type | Description |
---|---|---|
Available Index Options | nvarchar(35) | The options that are available. |
Default Value | int | The default values for the options. |
Members of the sysadmin fixed server role or the db_owner fixed database role can modify the AllowRowLocks and AllowPageLocks options for any user-defined indexes. Other users can modify options only for tables they own.
Any user can run sp_indexoption to generate a report listing index option values for all user-defined indexes.
This example reports the available index options for the PK_Customers index on the Customers table in the Northwind database.
USE Northwind
EXEC sp_indexoption @IndexNamePattern = 'Customers.PK_Customers'