Solved

return missing-backups

Posted on 2014-11-25
3
62 Views
Last Modified: 2014-11-25
can you suggest if there is more efficient (shorter) code or better logic to do this in sQL 2012?

http://www.mssqltips.com/tipImages2/2551_checkmissingbackups.txt
0
Comment
Question by:25112
3 Comments
 
LVL 45

Accepted Solution

by:
Vitor Montalvão earned 500 total points
ID: 40464833
Yes. Missing_Backups should be a temporary table (#Missing_Backups),
Also, I would avoid the UNION:
insert into #Missing_Backups  -- Assuming you are going to use temporary table
SELECT d.name AS Database, CASE b.Type
                      WHEN 'D' THEN 'Full' 
                       ELSE 'Trn'
                      END as Type,
       ISNULL(CONVERT(VARCHAR,b.backupdate,120),'NEVER') AS [Last Backup]
FROM sys.databases d
LEFT JOIN (SELECT database_name,type,MAX(backup_finish_date) backupdate FROM backupset
           GROUP BY database_name,type) b on d.name=b.database_name
WHERE (backupdate IS NULL OR backupdate < getdate()-1) 
  AND d.name <> 'tempdb'

Open in new window


The rest of the code is to transform in HTML to send the information by email. Depends on what you want to do with the information.
Also, the example considers missing backup as a database that don't has a backup from more than 1 day.
0
 
LVL 5

Author Comment

by:25112
ID: 40465239
Thank you.

Jim, I will remember that. the goal here was to make sure to use the latest syntax/provision, as our msdb files are big and planning to deploy in big servers with many databases.

thank you again.
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Join & Write a Comment

Suggested Solutions

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now