🕵️♂️
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
| -- run this in query window 1: | |
| SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED; | |
| SET DEADLOCK_PRIORITY HIGH; | |
| GO | |
| DECLARE @CMD nvarchar(max) = '' | |
| SELECT @CMD = CONCAT(@CMD, CHAR(10), 'KILL ', session_id) | |
| FROM sys.dm_exec_requests | |
| WHERE database_id = DB_ID('MyDB') -- replace MyDB with your DB 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
| SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED; | |
| SELECT | |
| Msg = CONCAT(N'Job "', j.name, N'" step ', s.step_id, N' ("', s.step_name,N'") ', | |
| , CARE WHEN s.retry_attempts > 0 THEN N'has retries enabled but ' ELSE N'' END | |
| , CASE WHEN (s.flags & 2) = 0 THEN N'Append is disabled (which may cause loss of info) ' ELSE N'Append is enabled ' END | |
| , CASE WHEN | |
| s.output_file_name NOT LIKE '%(TIME)%' | |
| AND s.output_file_name NOT LIKE '%(STRTTM)%' | |
| AND s.output_file_name NOT LIKE '%(STRTDT)%' |
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 @MaxEndTime datetime = DATEADD(HOUR, 2, GETDATE()) | |
| DECLARE @TimeLimitSeconds int; | |
| SET @TimeLimitSeconds = DATEDIFF(second, GETDATE(), @MaxEndTime) | |
| EXEC dbo.DatabaseIntegrityCheck | |
| @Databases = 'ALL_DATABASES', | |
| @CheckCommands = 'CHECKALLOC,CHECKCATALOG', | |
| --@PhysicalOnly = 'Y', | |
| @TimeLimit = @TimeLimitSeconds, |
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 @EndTime datetime = DATEADD(hour, 2, GETDATE()) -- Adjust the time limit as needed | |
| DECLARE @OlaHallengrenDBName sysname = DB_NAME() -- This script must run within the context of the database where Ola's maintenance solution was installed | |
| DECLARE @DBName sysname, @ObjNameFull nvarchar(4000), @ObjNameLean sysname, @SchName sysname | |
| DECLARE @CheckTime datetime, @LastCheckDate datetime, @ObjType sysname | |
| IF OBJECT_ID('tempdb..#Objects') IS NOT NULL DROP TABLE #Objects; | |
| CREATE TABLE #Objects | |
| ( | |
| DBName sysname, |
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
| /* | |
| https://learn.microsoft.com/en-us/sql/t-sql/statements/alter-table-transact-sql?view=sql-server-ver16#switch--partition-source_partition_number_expression--to--schema_name--target_table--partition-target_partition_number_expression- | |
| */ | |
| SET NOCOUNT ON; | |
| GO | |
| CREATE PARTITION FUNCTION PF1 (int) AS RANGE RIGHT FOR VALUES (0, 100) | |
| CREATE PARTITION SCHEME PS1 AS PARTITION PF1 ALL TO ([PRIMARY]); | |
| GO | |
| CREATE PARTITION FUNCTION PF2 (int) AS RANGE RIGHT FOR VALUES (0, 100, 200) | |
| CREATE PARTITION SCHEME PS2 AS PARTITION PF2 ALL TO ([PRIMARY]); |
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
| DROP TABLE IF EXISTS [dbo].[TestTable2]; | |
| DROP TABLE IF EXISTS [dbo].[TestTable1]; | |
| DROP TABLE IF EXISTS dbo.TestEdgeTable; | |
| DROP TABLE IF EXISTS dbo.TestNodeTable1; | |
| DROP TABLE IF EXISTS dbo.TestNodeTable2; | |
| DROP TABLE IF EXISTS dbo.TestNodeTable3; | |
| GO | |
| IF SCHEMA_ID('EitanTest') IS NOT NULL DROP SCHEMA EitanTest; | |
| GO | |
| CREATE SCHEMA EitanTest AUTHORIZATION dbo; |
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
| # SQL Database Project Build Configuration | |
| trigger: | |
| - master | |
| pool: | |
| vmImage: 'VS2017-Win2016' | |
| variables: | |
| solution: '**/*.sln' |
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
| -- Run this in the right SQL Sentry database | |
| --USE [SentryOne]; | |
| --USE [SQLSentry]; | |
| GO | |
| IF OBJECT_ID('[dbo].[heartbeat_log]') IS NULL | |
| BEGIN | |
| CREATE TABLE [dbo].[heartbeat_log]( | |
| [servername] [nvarchar](300) CONSTRAINT PK_Heartbeat_Log PRIMARY KEY CLUSTERED WITH(IGNORE_DUP_KEY=ON,DATA_COMPRESSION=PAGE), | |
| [heartbeatdate] [datetime] NULL, | |
| [ActualHeartbeatDate] [datetime] NULL |
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
| /* | |
| Check for low PAGE compression success rates | |
| ============================================ | |
| Author: Eitan Blumin | |
| Date: 2022-01-13 | |
| Based on blog post by Paul Randal: | |
| https://www.sqlskills.com/blogs/paul/the-curious-case-of-tracking-page-compression-success-rates/ | |
| */ | |
| DECLARE | |
| /* threshold parameters: */ |
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
| SET SHOWPLAN_XML ON; | |
| GO | |
| /* TODO: Add your test query here to get its estimated plan WITHOUT the hypothetical indexes */ | |
| GO | |
| SET SHOWPLAN_XML OFF; | |
| GO |
NewerOlder