March 23, 2009 at 11:13 am
Hello, I found this on this site and I am sure it does what I wanted, but as I cannot (due to policy) create any tables on the servers I am working on, could somebody please clarify that script just displays the details and doesnt create any databases or tables?
--Steve Bergkamp
--Script to list recovery model of databases.
declare @dblist table(db sysname,model char(45))
declare @dbname sysname,@model char(45)
insert @dblist(db)select name from master..sysdatabases where name not in ('master','model','tempdb','msdb')
select @dbname=min(db) from @dblist
while @dbname is not null
begin
select @model=cast(databasepropertyex(@dbname, 'Recovery') as char(45))
update @dblist set model=@model where db=@dbname
select @dbname=min(db) from @dblist where db>@dbname
end
select * from @dblist order by model
Thank you,
D.
March 23, 2009 at 11:19 am
The only "table" that is being created is a table variable. You should be fine using this script.
March 23, 2009 at 12:21 pm
Why so complicated?
Just use this:
select [db]=name, [model]=databasepropertyex(name, 'Recovery')
from master..sysdatabases
where name not in ('master','model','tempdb','msdb')
order by 2, 1
March 23, 2009 at 12:40 pm
Actually in 2005 ..
Simply this will give you that information also 🙂
SELECT * FROM sys.databases
Look for column Recovery_Model_Desc.
Thanks.
Mohit K. Gupta, MCITP: Database Administrator (2005), My Blog, Twitter: @SQLCAN[/url].
Microsoft FTE - SQL Server PFE
* Some time its the search that counts, not the finding...
* I didn't think so, but if I was wrong, I was wrong. I'd rather do something, and make a mistake than be frightened and be doing nothing. :smooooth:[/font]
March 23, 2009 at 2:16 pm
or
select name, DatabasePropertyEx(name,'Recovery') as model
from master.sys.sysdatabases
where dbid > 4
order by 2
this is fun. Next.
---------------------------------------------------------------------
March 23, 2009 at 3:02 pm
SELECT name as [Database Name], recovery_model_desc as [Recovery Model]
FROM sys.databases
WHERE name NOT IN ('master','model','tempdb','msdb')
GO
March 24, 2009 at 3:10 am
Now you see, this is why I come here, you guys are great and a real inspiration to me, yes that sounds cheesy, but I really mean it.
Thank you all very much!
D.
(1 hour later)
PS. What would be the SQL 2000 version of this?
SELECT name as [Database Name], recovery_model_desc as [Recovery Model]
FROM sys.databases
WHERE name NOT IN ('master','model','tempdb','msdb')
GO
March 24, 2009 at 6:46 am
2000 version is what I posted above
March 24, 2009 at 6:54 am
mine would also work in both 2000 and 2005 if you replaced the master.sys.sysdatabases with master..sysdatabases
its the reference to the sys schema and the column recovery_model_desc that are 2005 specific
---------------------------------------------------------------------
March 24, 2009 at 6:57 am
Ah, sorry, I didnt notice the difference. Thank you.
Regards,
D.
Viewing 10 posts - 1 through 9 (of 9 total)
You must be logged in to reply to this topic. Login to reply