I'm putting together an audit script (yes another one) to audit database option settings. I've got a full list of all databases and options, as well as a list of what databases have what options set.The question is, how do I update my full list of dbs and options to show what's in the other list? (What's set.) Hope I explained that right...Here's what I have so far. Please tell me if I'm going about this the wrong way.-- Get database options-- D Maxwell, June 2007-- Just a wrapper script for sp_dboption-- that gets the options for all dbs.-- First, get a list of possible options:create table ##all_options (option_name varchar(50) not null)insert into ##all_options exec master..sp_dboption-- Now, get the list of databases. create table ##dbnames (dbname varchar(25) not null)insert into ##dbnames select name from master..sysdatabases-- Now, get the set options for each database.-- First you need a table to hold them.create table ##dboptions_set ( dbname varchar(25) null, dboption varchar(50) not null)-- Now you can insert the db names and options into the table.while (select count(*) from ##dbnames) > 0 begin declare @db varchar(25) set @db = (select top 1 dbname from ##dbnames) -- We do this part first since it returns multiple rows. insert into ##dboptions_set(dboption) exec master..sp_dboption @dbname = @db -- Now we go back and fill in the db names. update ##dboptions_set set dbname = @db where dbname is null -- We're done with that one. Loop to the next one. delete from ##dbnames where dbname = @db end-- We have the list, now we make it useful. First, -- we need to build a report table that shows all DBs-- and all options. An actual good use of a cross join.-- Got to get the name list back, first.insert into ##dbnames select name from master..sysdatabasescreate table ##option_report ( dbname varchar(25) not null, dboption varchar(50) not null, setting tinyint null)insert into ##option_report select d.dbname, o.option_name, 0 from ##dbnames d cross join ##all_options o order by d.dbname-- Now we set the options as set or not set, -- according to the ##dboptions_set table.
...and I'm stuck. I've tried a few different methods, involving joins and EXISTS and such, but nothing is working so far. The logic escapes me...
Any suggestions or pointers on how to best accomplish this are appreciated.Thanks.-D.____________________________________________________________________________________"Believe in those who are seeking the truth. Doubt those who say they have found it." -Andre Gide