'D2'and d.status2 & v.number <> 0))return(0)endif @optvalue is not null and lower(@optvalue) not in ('true', 'false', 'on', 'off')beginraiserror(15241,-1,-1)return (1)end-- Use @optname and try to find the right option.-- If there isn't just one, print appropriate diagnostics and return.select @optcount = count(*) ,@fulloptname = min(name)from master.dbo.spt_valueswhere lower(name collate Latin1_General_CI_AS) like '%' + @optname + '%'and ((type = 'D'and number & @allstatopts <> 0and number not in (-1,@allstatopts))or (type = 'DC'and number & @allcatopts <> 0and number not in (-1,@allcatopts))or (type = 'D2'and number & @alloptopts <> 0and number not in (-1,@alloptopts)))-- If no option, show the user what the options are.if @optcount = 0beginraiserror(15011,-1,-1,@optnameIn)print ' 'select 'Settable database options:' = namefrom master.dbo.spt_valueswhere (type = 'D'and number & @allstatopts <> 0and number not in (-1,@allstatopts)) -- Eliminate non-option entriesor (type = 'DC'and number & @allcatopts <> 0and number not in (-1,@allcatopts))or (type = 'D2'and number & @alloptopts <> 0and number not in (-1,@alloptopts))order by namereturn (1)end-- If more than one option like @optname, show the duplicates and return.if @optcount > 1beginraiserror(15242,-1,-1,@optnameIn)print ' 'select duplicate_options = namefrom master.dbo.spt_valueswhere lower(name collate Latin1_General_CI_AS) like '%' + @optname + '%'and ((type = 'D'and number & @allstatopts <> 0and number not in (-1,@allstatopts))or (type = 'DC'and number & @allcatopts <> 0and number not in (-1,@allcatopts))or (type = 'D2'and number & @alloptopts <> 0and number not in (-1,@alloptopts)))return (1)end-- Just want to see current setting of specified option.if @optvalue is nullbeginselect OptionName = v.name,CurrentSetting = (casewhen ( ((v.number & d.status) = v.numberand v.type = 'D')or (d.category & v.number <> 0and v.type = 'DC')or (d.status2 & v.number <> 0and v.type = 'D2'))then 'ON'when not( ((v.number & d.status) = v.numberand v.type = 'D')or (d.category & v.number <> 0and v.type = 'DC')or (d.status2 & v.number <> 0and v.type = 'D2'))then 'OFF'end)from master.dbo.spt_values v, master.dbo.sysdatabases dwhere d.name=@dbnameand ((v.number & @allstatopts <> 0and v.number not in (-1,@allstatopts) -- Eliminate non-option entriesand v.type = 'D')or (v.number & @allcatopts <> 0and v.number not in (-1,@allcatopts) -- Eliminate non-option entriesand v.type = 'DC')or (v.number & @alloptopts <> 0and v.number not in (-1,@alloptopts) -- Eliminate non-option entriesand v.type = 'D2'))and lower(v.name) = lower(@fulloptname)return (0)endselect @catvalue = 0select @catvalue = numberfrom master.dbo.spt_valueswhere lower(name) = lower(@fulloptname)and type = 'DC'-- if setting replication option, call sp_replicationdboption directlyif (@catvalue <> 0)beginselect @alt_optvalue = (case lower(@optvalue)when 'true' then 'true'when 'on' then 'true'else 'false'end)select @alt_optname = (case @catvaluewhen 1 then 'publish'when 2 then 'subscribe'when 4 then 'merge publish'else quotename(@fulloptname, '''')end)select @exec_stmt = quotename(@dbname, '[') + '.dbo.sp_replicationdboption'EXEC @exec_stmt @dbname, @alt_optname, @alt_optvaluereturn (0)end-- call Alter Database to set options-- set option value in alter databaseselect @alt_optvalue = (case lower(@optvalue)when 'true' then 'ON'when 'on' then 'ON'else 'OFF'end)-- set option name in alter databaseselect @fulloptname = lower(@fulloptname)select @alt_optname = (case @fulloptnamewhen 'auto create statistics' then 'AUTO_CREATE_STATISTICS'when 'auto update statistics' then 'AUTO_UPDATE_STATISTICS'when 'autoclose' then 'AUTO_CLOSE'when 'autoshrink' then 'AUTO_SHRINK'when 'ansi padding' then 'ANSI_PADDING'when 'arithabort' then 'ARITHABORT'when 'numeric roundabort' then 'NUMERIC_ROUNDABORT'when 'ansi null default' then 'ANSI_NULL_DEFAULT'when 'ansi nulls' then 'ANSI_NULLS'when 'ansi warnings' then 'ANSI_WARNINGS'when 'concat null yields null' then 'CONCAT_NULL_YIELDS_NULL'when 'cursor close on commit' then 'CURSOR_CLOSE_ON_COMMIT'when 'torn page detection' then 'TORN_PAGE_DETECTION'when 'quoted identifier' then 'QUOTED_IDENTIFIER'when 'recursive triggers' then 'RECURSIVE_TRIGGERS'when 'default to local