SQL Stuff

Quickly Check Values In Sys.Configurations And Change If False

Here’s some very simplified sql logic that checks to see if a configuration is enabled, and subsequently changes those values if they are not enabled.
Note: If you ever want to use <> for NOT EQUAL TO then you’re doing the right thing. The alternative is to use this !=, but this is not portable. Use ANSI whenever possible. SQL Server interprets these two ‘not equal to’ constructs the same. In this example I’m simply usinge EQUAL (=)

 use master;
set nocount on

declare
@sao	int = (select cast([value] as int) from master.sys.configurations where [name] = 'show advanced options')
,	@bcd	int = (select cast([value] as int) from master.sys.configurations where [name] = 'backup compression default')
,	@xpc	int = (select cast([value] as int) from master.sys.configurations where [name] = 'xp_cmdshell')

if	@sao = 0	begin exec	master..sp_configure 'show advanced options', 1 reconfigure end
if	@bcd = 0	begin exec	master..sp_configure 'backup compression default', 1	reconfigure end
if	@xpc = 0	begin exec	master..sp_configure 'xp_cmdshell', 1 reconfigure end
Advertisements

Categories: SQL Stuff

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s