Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
vijays3
Constraint Violating Yak Guru
354 Posts |
Posted - 2010-04-27 : 04:39:24
|
Hi I need to create a which could generate the following detailsservernamedbnamerecoverymodecompatibilitylocation of data filelocation of log filelast date of full backuplast date of diff. backuplast date of tran backupThese are the columns in my tablei have have two scripts which are written seperately1..SELECT DBname=name,Status= convert(sysname,DatabasePropertyEx(name,'Status')), Updateability= convert(sysname,DatabasePropertyEx(name,'Updateability')) , UserAccess= convert(sysname,DatabasePropertyEx(name,'UserAccess')) , Recovery= convert(sysname,DatabasePropertyEx(name,'Recovery')) ,Version= convert(sysname,DatabasePropertyEx(name,'Version'))from sysdatabasesThis above script can get the half part of the requirement2 .select 'Databases and backups on server ' + @@servernameselect SUBSTRING(s.name,1,40) AS 'Database', CAST(b.backup_start_date AS char(11)) AS 'Backup Date ', CASE WHEN b.backup_start_date > DATEADD(dd,-1,getdate()) THEN 'Backup is current within a day' WHEN b.backup_start_date > DATEADD(dd,-7,getdate()) THEN 'Backup is current within a week' ELSE '*****CHECK BACKUP!!!*****' END AS 'Comment'from master..sysdatabases sLEFT OUTER JOIN msdb..backupset b ON s.name = b.database_name AND b.backup_start_date = (SELECT MAX(backup_start_date) FROM msdb..backupset WHERE database_name = b.database_name AND type = 'D') -- full database backups only, not log backupsWHERE s.name <> 'tempdb'ORDER BY s.name and this can get the remaining information..I am not being able to merge this two..could any please help me on thsi |
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-04-27 : 04:46:59
|
[code]select 'Databases and backups on server ' + @@servernameselect SUBSTRING(s.name,1,40) AS 'Database',Status= convert(sysname,DatabasePropertyEx(s.name,'Status')), Updateability= convert(sysname,DatabasePropertyEx(s.name,'Updateability')), UserAccess= convert(sysname,DatabasePropertyEx(s.name,'UserAccess')), Recovery= convert(sysname,DatabasePropertyEx(s.name,'Recovery')),Version= convert(sysname,DatabasePropertyEx(s.name,'Version')),CAST(b.backup_start_date AS char(11)) AS 'Backup Date ',CASE WHEN b.backup_start_date > DATEADD(dd,-1,getdate())THEN 'Backup is current within a day'WHEN b.backup_start_date > DATEADD(dd,-7,getdate())THEN 'Backup is current within a week'ELSE '*****CHECK BACKUP!!!*****'ENDAS 'Comment'from master..sysdatabases sLEFT OUTER JOIN msdb..backupset bON s.name = b.database_nameAND b.backup_start_date = (SELECT MAX(backup_start_date)FROM msdb..backupsetWHERE database_name = b.database_nameAND type = 'D') -- full database backups only, not log backupsWHERE s.name <> 'tempdb'ORDER BY s.name[/code] No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
vijays3
Constraint Violating Yak Guru
354 Posts |
Posted - 2010-04-27 : 04:56:58
|
some more question1.Thanks for your quick response ...but i tried to add compatibility column but for it all values are coming null although it should show 80,90.2.How can we get the last diff backup date and trans backup date as well3.will this query work on all the version of sql?quote: Originally posted by webfred
select 'Databases and backups on server ' + @@servernameselect SUBSTRING(s.name,1,40) AS 'Database',Status= convert(sysname,DatabasePropertyEx(s.name,'Status')), Updateability= convert(sysname,DatabasePropertyEx(s.name,'Updateability')), UserAccess= convert(sysname,DatabasePropertyEx(s.name,'UserAccess')), Recovery= convert(sysname,DatabasePropertyEx(s.name,'Recovery')),Version= convert(sysname,DatabasePropertyEx(s.name,'Version')),CAST(b.backup_start_date AS char(11)) AS 'Backup Date ',CASE WHEN b.backup_start_date > DATEADD(dd,-1,getdate())THEN 'Backup is current within a day'WHEN b.backup_start_date > DATEADD(dd,-7,getdate())THEN 'Backup is current within a week'ELSE '*****CHECK BACKUP!!!*****'ENDAS 'Comment'from master..sysdatabases sLEFT OUTER JOIN msdb..backupset bON s.name = b.database_nameAND b.backup_start_date = (SELECT MAX(backup_start_date)FROM msdb..backupsetWHERE database_name = b.database_nameAND type = 'D') -- full database backups only, not log backupsWHERE s.name <> 'tempdb'ORDER BY s.name No, you're never too old to Yak'n'Roll if you're too young to die.
|
 |
|
|
|
|
|
|