View UsersMemberships.sql
This file contains 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
USE StackOverflow; | |
GO | |
DROP TABLE IF EXISTS dbo.UsersMemberships; | |
CREATE TABLE dbo.UsersMemberships | |
(Id INT IDENTITY(1,1) PRIMARY KEY NONCLUSTERED, | |
UserId INT NOT NULL, | |
StartDate DATETIME NOT NULL, | |
EndDate DATETIME NOT NULL, | |
CancelledEarlyDate DATETIME NULL); |
View An Introduction to SQL Server Statistics with Playing Cards
This file contains 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 Server Statistics Explained with Playing Cards | |
v0.1 - 2020-08-14 | |
https://BrentOzar.com/go/learnstats | |
This first RAISERROR is just to make sure you don't accidentally hit F5 and | |
run the entire script. You don't need to run this: | |
*/ | |
RAISERROR(N'Oops! No, don''t just hit F5. Run these demos one at a time.', 20, 1) WITH LOG; | |
GO |
View Fun With ASCII
This file contains 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
CREATE DATABASE [٠০౦০٠]; | |
GO | |
USE [٠০౦০٠]; | |
GO | |
CREATE SCHEMA [٠০౦০٠]; | |
GO | |
CREATE TABLE [٠০౦০٠].[٠০౦০٠]([٠০౦০٠] NVARCHAR(20), [۰০౦০٠] NVARCHAR(20), [٠০౦০۰] NVARCHAR(20), [۰০౦০۰] NVARCHAR(20)); | |
GO | |
CREATE UNIQUE CLUSTERED INDEX [٠০౦০٠] ON [٠০౦০٠].[٠০౦০٠]([٠০౦০٠], [۰০౦০٠], [٠০౦০۰], [۰০౦০۰]); | |
GO |
View PlanCacheByDateAndHour.sql
This file contains 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 Server Plan Cache History by Date & Time | |
Brent Ozar, 2018/07/03 - https://BrentOzar.com/go/plansbydate | |
This is free and unencumbered software released into the public domain. | |
Anyone is free to copy, modify, publish, use, compile, sell, or | |
distribute this software, either in source code form or as a compiled | |
binary, for any purpose, commercial or non-commercial, and by any | |
means. |
View TopQueries.sql
This file contains 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
USE StackOverflow; | |
GO | |
IF OBJECT_ID('dbo.usp_Q7521') IS NULL | |
EXEC ('CREATE PROCEDURE dbo.usp_Q7521 AS RETURN 0;') | |
GO | |
ALTER PROC dbo.usp_Q7521 @UserId INT AS | |
BEGIN | |
/* Source: http://data.stackexchange.com/stackoverflow/query/7521/how-unsung-am-i */ |
View SQL Server 2019 inline function bug
This file contains 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
ALTER DATABASE CURRENT SET COMPATIBILITY_LEVEL = 140; | |
GO | |
CREATE OR ALTER FUNCTION dbo.Test() | |
RETURNS INT AS | |
BEGIN | |
DECLARE @i BIGINT; | |
SELECT TOP 1 @i = CHECKSUM(*) | |
FROM master.dbo.spt_values; | |
RETURN 1; |
View sys.index_resumable_operations.sql
This file contains 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.DiningRoomTable; | |
GO | |
CREATE TABLE dbo.DiningRoomTable (Id INT IDENTITY(1,1) PRIMARY KEY CLUSTERED, Stuffing CHAR(1000)); | |
INSERT INTO dbo.DiningRoomTable (Stuffing) | |
SELECT 'Stuff' | |
FROM sys.messages; | |
GO | |
CREATE INDEX IX_Stuffing ON dbo.DiningRoomTable(Stuffing) | |
WITH (ONLINE = ON, RESUMABLE = ON); |
View How to Make SELECT COUNT(*) Queries Crazy Fast.sql
This file contains 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
USE StackOverflow; | |
GO | |
DropIndexes; | |
GO | |
ALTER DATABASE CURRENT SET COMPATIBILITY_LEVEL = 140; | |
GO | |
/* Check the table's size: */ | |
sp_BlitzIndex @TableName = 'Votes'; | |
GO |
View Branching proc.sql
This file contains 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
CREATE PROCEDURE dbo.GetUnshippedOrders @IsShipped bit | |
AS | |
BEGIN | |
SET NOCOUNT ON; | |
IF @IsShipped = 1 | |
EXEC dbo.GetUnshippedOrders_UsesFilteredIndex | |
ELSE | |
SELECT OrderID, OrderDate FROM dbo.Orders WHERE IsShipped = @IsShipped; | |
END | |
GO |
View sp_Blitz_as_script.sql
This file contains 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 | |
@Help TINYINT = 0 , | |
@CheckUserDatabaseObjects TINYINT = 1 , | |
@CheckProcedureCache TINYINT = 0 , | |
@OutputType VARCHAR(20) = 'TABLE' , | |
@OutputProcedureCache TINYINT = 0 , | |
@CheckProcedureCacheFilter VARCHAR(10) = NULL , | |
@CheckServerInfo TINYINT = 0 , | |
@SkipChecksServer NVARCHAR(256) = NULL , | |
@SkipChecksDatabase NVARCHAR(256) = NULL , |
NewerOlder