Skip to content

Instantly share code, notes, and snippets.

View EitanBlumin's full-sized avatar
🕵️‍♂️
Figuring it out

Eitan Blumin EitanBlumin

🕵️‍♂️
Figuring it out
View GitHub Profile
@EitanBlumin
EitanBlumin / Online Index Operations without Enterprise.sql
Last active January 10, 2024 10:36
Generate Script to allow performing ONLINE index operations and heavy changes on huge tables, without needing Enterprise edition of SQL Server
/***********************************************************************************
Copyright: Eitan Blumin (c) 2018
https://gist.github.com/EitanBlumin/79222fc2be5163cec828d0a69270a0ab
***********************************************************************************/
-- TODO: Rename the _NEW object names to their original names (primary key, default and check constraints)
-- TODO: Identify constraints with NOCHECK
GO
IF OBJECT_ID('tempdb..#PrintMax', 'P') IS NOT NULL DROP PROCEDURE #PrintMax;
@EitanBlumin
EitanBlumin / Review SQL Instance Best Practices.sql
Last active December 24, 2020 12:07
Condensed SQL Server Checkup of most common and impactful best practices
/*
Author: Eitan Blumin (t: @EitanBlumin | b: eitanblumin.com)
Date: February, 2019
Description:
This is a condensed SQL Server Checkup of most common and impactful best practices.
Some of the checks are based on BP_Check.sql in Tiger Toolbox (by Pedro Lopez)
*/
DECLARE
@NumOfMinutesBackToCheck INT = 360,
@MinutesBackToCheck INT = 360,
-- Based on script by Jason Selburg
-- https://www.sqlservercentral.com/Forums/Topic279460-150-1.aspx
-- http://www.sqlservercentral.com/scripts/Miscellaneous/31733/
USE ReportServer
GO
IF OBJECT_ID(N'[dbo].[data_driven_subscription]', 'P') IS NOT NULL
DROP PROCEDURE [dbo].[data_driven_subscription]
GO
/************** Find Orphaned Records **************
Author: Eitan Blumin (t: @EitanBlumin | b: eitanblumin.com)
More info: https://eitanblumin.com/2018/11/06/find-and-fix-untrusted-foreign-keys-in-all-databases/
****************************************************/
DECLARE
@ForeignKeyName SYSNAME = 'FK_MyTable_MyOtherTable'
, @PrintOnly BIT = 0
DECLARE
@FKId INT,
@EitanBlumin
EitanBlumin / Get Recent SQL Error Log Errors.sql
Created November 22, 2018 08:48
Coalesces error messages from SQL Error Log into one row per exception
DECLARE @MinutesBackToCheck INT = 10;
SET NOCOUNT ON;
DECLARE @start DATETIME;
SET @start=DATEADD(MINUTE,-@MinutesBackToCheck,GETDATE());
DECLARE @errors AS TABLE
(
ID INT IDENTITY(1,1) NOT NULL PRIMARY KEY CLUSTERED,
LogDate DATETIME,
@EitanBlumin
EitanBlumin / Generate Procedure Unit Test with Auto-Comparison.sql
Last active September 17, 2020 02:06
Use this script to generate and run a "unit test" for two stored procedures. This script is good as a "sanity check" of sorts, that makes sure the operational effect of two procedures is the same. The script also prints out the duration of each procedure in milliseconds.
/**************************************************************************************************/
/* Generate Procedure Unit Test with Automatic Comparison */
/**************************************************************************************************/
-- Author: Eitan Blumin
-- Date: 2018-11-21
-- Description: Use this script to generate and run a "unit test" for two stored procedures.
-- Each procedure is considered to be affecting one or more database tables.
-- The contents of these tables can be compared before and after each unit test,
-- and the results of each of the two stored procedures can be compared.
/*
Fully Parameterized Search Query
--------------------------------
Copyright Eitan Blumin (c) 2018; email: eitan@madeiradata.com
You may use the contents of this SQL script or parts of it, modified or otherwise
for any purpose that you wish (including commercial).
Under the single condition that you include in the script
this comment block unchanged, and the URL to the original source, which is:
http://www.eitanblumin.com/
@EitanBlumin
EitanBlumin / PrintMax_Minified_Temporary_Procedure.sql
Last active September 2, 2020 09:51
This is a minified version of the PrintMax procedure (originally written by Ben Dill). It's created as a temporary procedure.
IF OBJECT_ID('tempdb..#PrintMax') IS NOT NULL DROP PROC #PrintMax;
GO
/*
Author: Eitan Blumin (t: @EitanBlumin | b: eitanblumin.com)
Description:
This is a minified version of the PrintMax procedure (originally written by Ben Dill).
It's created as a temporary procedure.
*/
CREATE PROCEDURE #PrintMax @str NVARCHAR(MAX)
AS
param (
[Parameter(Mandatory)][string] $GitHubToken,
[Parameter(Mandatory)][string] $GitHubOwner,
[Parameter(Mandatory)][string] $GitHubRepo,
[Parameter(Mandatory)][string] $SourceTrelloJsonFile,
[string[]] $TrelloLists,
[bool] $UpdateExistingIssuesByTitle = $true,
[bool] $AddNonExistingIssues = $true,
[bool] $Logging = $true
)
@EitanBlumin
EitanBlumin / Parse Vulnerability Assessment Results File into HTML.sql
Last active November 11, 2020 07:02
Parse JSON scan results file from a SQL Vulnerability Assessment Tool into a relational structure https://eitanblumin.com/sql-vulnerability-assessment-tool-rules-reference-list/
/******************************************************************
Parse SQL Vulnerability Assessment Tool Results
***********************************************
Author: Eitan Blumin | https://www.eitanblumin.com
Description:
Use this script to parse a Vulnerability Assessment Tool
results file into a relational structure.
This will output the T-SQL queries used by VAT behind the scenes
and their respective meta-data, as displayed in the VAT.