Thursday, 11 May 2017

T-SQL Script, It returns all Backups history information:

Using this script, you can find different types of information like Backup media, Type of Backup, Taken Duration.
 BOL
T-SQL Script, It returns all Backups history information:

SELECT
       bs.server_name AS ServerName,
       bs.database_name AS DatabaseName
       ,CASE bs.type
              WHEN 'D' THEN 'Full'
              WHEN 'I' THEN 'Differential'
              WHEN 'L' THEN 'Transaction Log'
       END AS BackupType
       ,CAST(DATEDIFF
              (SECOND,bs.backup_start_date,bs.backup_finish_date)
              AS VARCHAR(4)) + ' ' + 'Seconds' AS TotalTimeTaken
       ,bs.backup_start_date AS BackupStartDate
       ,CAST(bs.first_lsn AS VARCHAR(50)) AS FirstLSN
       ,CAST(bs.last_lsn AS VARCHAR(50)) AS LastLSN
       ,bmf.physical_device_name AS PhysicalDeviceName
       ,CAST(CAST(bs.backup_size / 1000000 AS INT) AS VARCHAR(14))
              + ' ' + 'MB' AS BackupSize
       ,bs.recovery_model AS RecoveryModel
FROM msdb.dbo.backupset AS bs
INNER JOIN msdb.dbo.backupmediafamily AS bmf
       ON bs.media_set_id = bmf.media_set_id
WHERE bs.database_name = 'master'
ORDER BY
       backup_start_date DESC

       ,backup_finish_date

No comments:

Post a Comment

Disable CDC at table level

 How to Disable CDC( Change Data Capture) for tables Change Data Capture (cdc) property is disabled as default.  here I will Query you how t...