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 / Find_Top_Exec_Plans_to_Optimize.sql
Last active November 15, 2022 02:06
T-SQL script to find cached execution plans with good potential for performance optimization (warnings, missing indexes, bad operators, etc.)
/*
=======================================================
Find Top Exec Plans to Optimize
=======================================================
Author: Eitan Blumin | eitanblumin.com , madeiradata.com
Date: 2020-08-12
Description:
Use this script to discover execution plans with a good
potential for performance optimization.
Finds execution plans with warnings and problematic operators.
@EitanBlumin
EitanBlumin / drop jobs and jobs_internal schemas.sql
Created April 3, 2020 10:21
Generate commands to drop the "jobs" and "jobs_internal" schemas and all of their objects
SELECT
'ALTER TABLE ' + QUOTENAME(SCHEMA_NAME(schema_id)) + '.' + QUOTENAME(OBJECT_NAME(parent_object_id))
+ ' DROP CONSTRAINT ' + QUOTENAME(name)
FROM sys.foreign_keys
WHERE schema_id IN ( SCHEMA_ID('jobs'), SCHEMA_ID('jobs_internal') )
ORDER BY
CASE schema_id WHEN SCHEMA_ID('jobs') THEN 1 ELSE 2 END ASC
SELECT
'DROP VIEW ' + QUOTENAME(SCHEMA_NAME(schema_id)) + '.' + QUOTENAME(name)
@EitanBlumin
EitanBlumin / simplest_alternative_to_sp_MSforeachdb.sql
Last active August 29, 2022 10:05
The simplest possible alternative to sp_MSforeachdb
/*
Author: Eitan Blumin | https://eitanblumin.com | https://madeiradata.com
Description:
This is the simplest possible alternative to sp_MSforeachdb which is not too great.
Instructions:
1. Replace the contents of the @Command variable with the command you want to run INSIDE each database.
2. Replace the contents of the @Parameters variable with the parameters you want the command to receive.
3. Add parameters as needed, given @p1 as an example.
4. Change the database filter predicates in the cursor declaration, as needed.
USE AdventureWorks2008R2
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF OBJECT_ID('Purchasing.usp_AT_uPurchaseOrderDetail', 'P') IS NOT NULL
DROP PROCEDURE Purchasing.usp_AT_uPurchaseOrderDetail;
GO
CREATE PROCEDURE Purchasing.usp_AT_uPurchaseOrderDetail
@EitanBlumin
EitanBlumin / Parse Vulnerability Assessment Result Files into HTML.sql
Last active June 3, 2022 09:32
Script to parse multiple Vulnerability Assessment Tool result files into an HTML reference list ( 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 and save in an HTML page.
This will output the T-SQL queries used by VAT behind the scenes
and their respective meta-data, as displayed in the VAT.
@EitanBlumin
EitanBlumin / InstancePropertiesComparison.sql
Last active May 15, 2022 14:48
Compare SQL Server Instance Properties
----------------------------------------------------------------------------------
-- Author: Eitan Blumin (t: @EitanBlumin | b: eitanblumin.com)
-- Date: 26/06/18
-- Description:
-- Compares server level objects and definitions as outputted by the first script (InstancePropertiesGenerateForCompare.sql).
--
-- Instructions:
-- Run InstancePropertiesGenerateForCompare.sql on each server. Save output to a CSV file.
-- Use this script ( InstancePropertiesComparison.sql ) to load the files into a table, and output any differences
-- Don't forget to change file paths accordingly.
@EitanBlumin
EitanBlumin / SQLDatabaseYAMLBuildConfiguration.yml
Last active May 8, 2022 08:20 — forked from jpvelasco/SQLDatabaseYAMLBuildConfiguration.yml
SQL YAML Build Configuration for Azure Pipelines
# SQL Database Project Build Configuration
trigger:
- master
pool:
vmImage: 'VS2017-Win2016'
variables:
solution: '**/*.sln'
@EitanBlumin
EitanBlumin / SQLSentry_Heartbeat_Monitoring.sql
Last active April 26, 2022 13:31
Example job command to implement self-monitoring for SQL Sentry monitoring service hearbeats
-- 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
@EitanBlumin
EitanBlumin / Extended Properties as Database Global Variables.sql
Created June 14, 2021 07:29
Use Extended Properties as Database Global Variables
/*
================================================
Extended Properties as Database Global Variables
================================================
Author: Eitan Blumin | https://madeiradata.com | https://eitanblumin.com
Date: 2021-06-04
Description:
Use this sample script as a template or starting point
for when you want to utilize extended properties
to save and retrieve values as if using "global" variables
@EitanBlumin
EitanBlumin / Foreign_Key_Hierarchy_Tree.sql
Created January 7, 2021 16:07
T-SQL script to retrieve the hierarchy tree for a given table, based on foreign key references.
/*
Retrieve Foreign Key Hierarchy Tree
===================================
Author: Eitan Blumin | https://eitanblumin.com | https://madeiradata.com
Date: 2021-01-07
Description:
Retrieve the hierarchy tree for a given table,
based on foreign key references.
Use this script to map out your entity relational structure,
see which foreign keys are dependent on a given table,