Archive for the ‘SQL Server’ Category

Usually you would like to know last time a database was restored. This is very handy script to show you the details.


WITH LastRestores AS
(
SELECT
DatabaseName = [d].[name] ,
[d].[create_date] ,
[d].[compatibility_level] ,
[d].[collation_name] ,
r.*,
RowNum = ROW_NUMBER() OVER (PARTITION BY d.Name ORDER BY r.[restore_date] DESC)
FROM master.sys.databases d
LEFT OUTER JOIN msdb.dbo.[restorehistory] r ON r.[destination_database_name] = d.Name
)
SELECT *
FROM [LastRestores]
WHERE [RowNum] = 1

You can simply get the details from dbo.restorehistory from MSDB databases. However, the above script will provide more details.

Advertisements

SQL Server preformance

Posted: April 11, 2015 in SQL Server

Turn on flag – DBCC TRACEON 1222

Start monitoring the SQL Server Event Logs.