This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| DECLARE @SchemaName VARCHAR(100); | |
| DECLARE @TableName VARCHAR(256); | |
| DECLARE @IndexName VARCHAR(256); | |
| DECLARE @ColumnName VARCHAR(100); | |
| DECLARE @is_unique VARCHAR(100); | |
| DECLARE @IndexTypeDesc VARCHAR(100); | |
| DECLARE @FileGroupName VARCHAR(100); | |
| DECLARE @is_disabled VARCHAR(100); | |
| DECLARE @IndexOptions VARCHAR(MAX); | |
| DECLARE @IndexColumnId INT; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| SELECT c.Name, | |
| c.[Path], | |
| COUNT(*) AS TimesRun, | |
| MAX(l.TimeStart) AS [LastRun], | |
| ( | |
| SELECT SUBSTRING( | |
| ( | |
| SELECT CAST(', ' AS VARCHAR(MAX))+CAST(c1.Name AS VARCHAR(MAX)) | |
| FROM [ReportServer].[dbo].[Catalog] AS c | |
| INNER JOIN [ReportServer].[dbo].[DataSource] AS d ON c.ItemID = d.ItemID |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| WITH RedundantQueries | |
| AS (SELECT TOP 10 | |
| query_hash, | |
| COUNT(query_hash) AS PlansCached, | |
| COUNT(DISTINCT (query_hash)) AS DistinctPlansCached, | |
| MIN(creation_time) AS FirstPlanCreationTime, | |
| MAX(creation_time) AS LastPlanCreationTime, | |
| SUM(total_worker_time) AS Total_CPU_ms, | |
| SUM(total_elapsed_time) AS Total_Duration_ms, | |
| SUM(total_logical_reads) AS Total_Reads, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| SELECT T.DatabaseName, | |
| T.ObjectId, | |
| T.ObjectName, | |
| T.IndexId, | |
| T.IndexDescription, | |
| CONVERT(DECIMAL(16, 1), (SUM(T.avg_record_size_in_bytes * T.record_count) / (1024.0 * 1024))) AS [IndexSize(MB)], | |
| T.lastupdated AS [StatisticLastUpdated], | |
| T.AvgFragmentationInPercent | |
| FROM | |
| ( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| DECLARE @TraceFileName NVARCHAR(400); | |
| SELECT TOP 1 | |
| @TraceFileName = path | |
| FROM sys.traces | |
| WHERE is_default = 1; | |
| SELECT * | |
| FROM sys.fn_trace_gettable(@TraceFileName, DEFAULT) AS t | |
| WHERE ( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| WITH LastRestores AS | |
| ( | |
| SELECT [rs].[destination_database_name] | |
| ,[rs].[restore_date] | |
| ,[bs].[backup_start_date] | |
| ,[bs].[backup_finish_date] | |
| ,[bs].[database_name] AS [source_database_name] | |
| ,[bmf].[physical_device_name] AS [backup_file_used_for_restore] | |
| ,RowNum = ROW_NUMBER() OVER (PARTITION BY [rs].[destination_database_name] ORDER BY rs.[restore_date] DESC) | |
| FROM msdb..restorehistory rs |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| SELECT t.name, | |
| MAX(us.last_user_seek) AS last_user_seek, | |
| MAX(us.last_user_scan) AS last_user_scan, | |
| MAX(us.last_user_lookup) AS last_user_lookup, | |
| MAX(us.last_user_update) AS last_user_update | |
| FROM sys.dm_db_index_usage_stats AS us | |
| JOIN sys.tables AS t | |
| ON t.object_id = us.object_id | |
| WHERE us.database_id = DB_ID() | |
| GROUP BY t.name; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| SELECT j.name, | |
| j.description, | |
| a.start_execution_date | |
| FROM msdb.dbo.sysjobs AS j | |
| INNER JOIN msdb.dbo.sysjobactivity AS a | |
| ON j.job_id = a.job_id | |
| WHERE a.start_execution_date > DATEADD(dd, -14, GETDATE()) | |
| AND j.enabled = 1 | |
| AND a.start_execution_date IN | |
| ( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| select CASE (ss.freq_subday_type) | |
| WHEN 1 then left(stuff((stuff((replicate('0', 6 - len(ss.active_start_time)))+ convert(varchar(6),ss.active_start_time),3,0,':')),6,0,':'),8) | |
| WHEN 2 then 'Every ' + convert(varchar(10),ss.freq_subday_interval) + ' seconds' | |
| WHEN 4 then 'Every ' + convert(varchar(10),ss.freq_subday_interval) + ' minutes' | |
| WHEN 8 then 'Every ' + convert(varchar(10),ss.freq_subday_interval) + ' hours' | |
| ELSE '??' | |
| END AS [Time], | |
| s.Name | |
| from msdb.dbo.sysjobs AS s | |
| left join msdb.dbo.sysjobschedules AS sj on S.job_id = SJ.job_id |