Displays or changes database options, and enables the asynchronous log service feature.
sp_dboption [dbname, optname, optvalue [, dockpt]]
You can turn on more than one database option at a time. You cannot change database options inside a user-defined transaction.
sp_dboption
Settable database options
database_options ------------------------ abort tran on log full allow incremental dumps allow nulls by default allow wide dol rows async log service auto identity dbo use only ddl in tran deallocate first text page deferred table allocation delayed commit enforce dump tran sequence erase residual data full logging for all full logging for alter table full logging for reorg rebuild full logging for select into identity in nonunique index no chkpt on recovery no free space acctg read only scratch database select into/bulkcopy/pllsort single user trunc log on chkpt trunc. log on chkpt. unique auto_identity index
1> use pubs2 2> go 1> master..sp_dboption pubs2, "read", true 2> go
Database option 'read only' turned ON for database 'pubs2'. Running CHECKPOINT on database 'pubs2' for option 'read only' to take effect. (return status = 0)
The read string uniquely identifies the read only option from among all available database options. Note the use of quotes around the keyword read.
1> use pubs2 2> go 1> master..sp_dboption pubs2, "read", false, 0 2> go
Database option 'read only' turned OFF for database 'pubs2'. Run the CHECKPOINT command in the database that was changed. (return status = 0)
To manually perform a checkpoint on pubs2, enter:
1> checkpoint 2> go
use pubs2 go master..sp_dboption pubs2, "select into", true go
use mydb go master..sp_dboption mydb, "auto identity", true go
use master go sp_dboption mydb, "identity in nonunique index", true go use mydb go
use master go sp_dboption pubs2, "unique auto_identity index", true go use pubs2 go
sp_dboption "mydb", "async log service", true use mydb
sp_dboption "mydb", "async log service", false use mydb
sp_dboption 'big_db', 'enforce dump tran sequence', true
create database mydb on datadev=20 log on logdev=10 go
CREATE DATABASE: allocating 10240 logical pages (20.0 megabytes) on disk 'datadev' (10240 logical pages requested). CREATE DATABASE: allocating 5120 logical pages (10.0 megabytes) on disk 'logdev' (5120 logical pages requested). Database 'mydb' is now online.
sp_dboption "mydb", "full logging for select into", "true" go
Database option 'full logging for select into' turned ON for database 'mydb'. Running CHECKPOINT on database 'mydb' for option 'full logging for select into' to take effect. (return status = 0)
sp_dboption "mydb", "full logging for alter table", "true" go
Database option 'full logging for alter table' turned ON for database 'mydb'. Running CHECKPOINT on database 'mydb' for option 'full logging for alter table' to take effect. (return status = 0)
sp_helpdb mydb go
name db_size owner dbid created durability status ---- ------- ----- ---- ------------ --------- ----------------------- mydb 30.0 MB sa 5 Dec 16, 2010 full full logging for select into/alter table (1 row affected) device_fragments size usage created free kbytes ----------------- ------- ---------- ------------------- -------------- datadev 20.0 MB data only Dec 16 2010 6:08PM 18696 logdev 10.0 MB log only Dec 16 2010 6:08PM not applicable -------------------------------------------------------------- log only free kbytes = 10184 (return status = 0) 1>
sp_dboption mydb, "allow incremental dumps", true
sp_dboption pubs2, 'deferred table allocation', true
sp_dboption dbname, "erase residual data", true
The option to erase residual data is turned on for table t1 because it is set at the database level, so that both the drop table and truncate table commands for t1 result in the cleanup of all residual data from its pages.
create database db1 go sp_dboption db1, "erase residual data", true go use db1 go create table t1 (col int) go insert t1 values ... go create table t2 (col1 int, col2 char(10)) with "erase residual data" off go truncate table t1 go drop table t1 go truncate table t2 go drop table t2 go
create database db1 go use db1 go create table t1 (col int) go sp_dboption db1, "erase residual data", true go create table t2 (col1 int, col2 char(10)) go create table t3 (col1 int, col2 char(10)) with "erase residual data" off go truncate table t1 go truncate table t2 go truncate table t3 go
sp_dboption mydb, "deallocate first text page", true
When you enable the "erase residual data" setting at the database level, any operation that results in deallocation is followed by the cleaning of its pages. By default, this option is disabled
You cannot change master database option settings.
If you enter an ambiguous value for optname, an error message appears. For example, two of the database options are dbo use only and read only. Using “only” for the optname parameter generates a message because it matches both names. The complete names that match the string supplied are printed out so that you can see how to make the optname more specific.
To display a list of database options, execute sp_dboption with no parameters from inside the master database.
For a report on which database options are set in a particular database, execute sp_helpdb.
The no chkpt on recovery option disables the trunc log on chkpt option when both are set with sp_dboption for the same database. This conflict is especially possible in the tempdb database which has trunc log on chkpt set to on as the default.
The database owner or system administrator can set or unset particular database options for all new databases by executing sp_dboption on model.
After sp_dboption has been executed, the change does not take effect until the checkpoint command is issued in the database for which the option was changed.
alter table, checkpoint, create default, create index, create procedure, create rule, create schema, create table, create trigger, create view, drop default, drop index, drop procedure, drop rule, drop table, drop trigger, drop view, grant, revoke, select in Reference Manual: Commands
See the System Administration Guide for more information on database options.
bcp in the Utility Guide
The permission checks for sp_dboption differ based on your granular permissions settings.
Setting | Description |
---|---|
Enabled | With granular permissions enabled, you must be the database owner or a user with own database privilege on the database. Any user can display database options. |
Disabled | With granular permissions disabled, you must be the database owner or a user with sa_role. Any user can display database options. A user aliased to the database owner cannot execute sp_dboption to change database options. |
Values in event and extrainfo columns from the sysaudits table are:
Information | Values |
---|---|
Event | 38 |
Audit option | exec_procedure |
Command or access audited | Execution of a procedure |
Information in extrainfo |
|