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 Invalid Records by Check Constraint.sql
Last active November 16, 2021 09:40
Find the records which cause your not trusted check constraint to fail (more info: https://eitanblumin.com/2018/11/06/find-and-fix-untrusted-foreign-keys-in-all-databases/ )
/************** Find Invalid Records ***************
Author: Eitan Blumin
****************************************************/
DECLARE
@Constraint SYSNAME = 'CK_Name'
, @PrintOnly BIT = 0
DECLARE
@TableID INT,
@CheckDefinition NVARCHAR(MAX),
@EitanBlumin
EitanBlumin / zendesk_open_ticket.ps1
Created August 22, 2019 10:19
Powershell script to open Zendesk support tickets, or add comment to an existing ticket (based on requester and subject). Useful for automatic monitoring and alerting systems.
param
(
[string] $Subject = "This is a test ticket from Powershell",
[string] $Body = "This is test description",
[string] $RequesterEmail = "[email protected]",
[string] $SourceServer = "SqlDev2016",
[string] $SQLVersion = "2016",
[string] $SQLEdition = "Developer",
[string] $Priority = "low",
[string] $StartDate = "2018-04-17 23:30",
@EitanBlumin
EitanBlumin / ultimate_compression_savings_estimation_whole_database.sql
Last active June 26, 2024 03:06
This ultimate script performs compression savings estimation check for an ENTIRE database, includes comparison between PAGE and ROW compression types, cautionary table size checks, AND it generates the remediation scripts for you! (more info: https://eitanblumin.com/2020/02/18/ultimate-compression-savings-estimation-script-entire-database/ )
----------------------------------------------------------------
-------- Ultimate Compression Savings Estimation Check ---------
----------------------------------------------------------------
-- Author: Eitan Blumin | https://www.eitanblumin.com
-- Create Date: 2019-12-08
-- Source: http://bit.ly/SQLCompressionEstimation
-- Full Link: https://gist.github.com/EitanBlumin/85cf620f7267b234d677f9c3027fb7ce
-- GitHub Repo: https://github.com/MadeiraData/MadeiraToolbox/blob/master/Utility%20Scripts/ultimate_compression_savings_estimation_whole_database.sql
-- Blog: https://eitanblumin.com/2020/02/18/ultimate-compression-savings-estimation-script-entire-database/
----------------------------------------------------------------
@EitanBlumin
EitanBlumin / Generate_recommendations_for_clustered_indexes.sql
Last active January 30, 2023 20:24
Use existing non-clustered index usage stats, and missing index stats, to generate clustered-index recommendations for heap tables (more info: https://eitanblumin.com/2019/12/30/resolving-tables-without-clustered-indexes-heaps/ )
-------------------------------------------------------
------ Generate Clustered Index Recommendations -------
-------------------------------------------------------
-- Author: Eitan Blumin | https://www.eitanblumin.com
-- More info: https://eitanblumin.com/2019/12/30/resolving-tables-without-clustered-indexes-heaps/
-------------------------------------------------------
-- Description:
-- ------------
-- This script finds all heap tables, and "guestimates" a clustered index recommendation for each.
-- The script implements the following algorithm:
/**************************************************************************
Check Index Fragmentation based on Page Fullness and Fill Factor
***************************************************************************
Author: Eitan Blumin | https://www.eitanblumin.com
Version History:
2020-10-20 Added @MaxDOP parameter, and better comments & indentation
2020-01-07 First version
Description:
This script was inspired by Erik Darling's blog post here:
@EitanBlumin
EitanBlumin / helper_script_for_adding_schemabinding_to_scalar_functions.sql
Last active December 24, 2020 12:06
Helper T-SQL script for adding SCHEMABINDING on scalar functions (checks in ALL databases on the server)
/*
Author: Eitan Blumin | https://www.eitanblumin.com
Description:
Helper T-SQL script for adding SCHEMABINDING on scalar functions (checks in ALL databases on the server)
Added support for Azure SQL DB: Performs the same check across schemas instead of across databases
Instructions:
1. Run the script to detect all scalar functions with disabled SCHEMABINDING, that can potentially have it enabled.
@EitanBlumin
EitanBlumin / check_untrusted_check_constraints.sql
Last active November 16, 2021 09:39
Find and check untrusted Check Constraints in all active databases (more info: https://eitanblumin.com/2018/11/06/find-and-fix-untrusted-foreign-keys-in-all-databases/ )
IF OBJECT_ID('tempdb..#tmp') IS NOT NULL DROP TABLE #tmp;
CREATE TABLE #tmp (DBName SYSNAME, SchemaName SYSNAME, TableName SYSNAME, FullTableName AS QUOTENAME(SchemaName) + N'.' + QUOTENAME(TableName), UntrustedObject SYSNAME);
DECLARE @CMD NVARCHAR(MAX)
SET @CMD = N'SELECT DB_NAME(), OBJECT_SCHEMA_NAME(parent_object_id), OBJECT_NAME(parent_object_id), [name]
FROM sys.check_constraints
WHERE is_not_trusted = 1 AND is_not_for_replication = 0 AND is_disabled = 0;'
IF CONVERT(varchar(300),SERVERPROPERTY('Edition')) = 'SQL Azure'
BEGIN
@EitanBlumin
EitanBlumin / Get Top Query Plans with Warnings from Cache.sql
Last active November 16, 2021 09:07
Get Top Query Plans with Warnings from SQL Plan Cache
/***************************************************************************
Get Top Query Plans with Warnings from Cache
--------------------------------------------
Author: Eitan Blumin | https://www.eitanblumin.com
Change Log:
2020-01-29 - Added a few more warnings from sp_BlitzCache: https://www.brentozar.com/blitzcache/
2020-01-12 - First version
****************************************************************************/
DECLARE
@EitanBlumin
EitanBlumin / TempDB Sizing Check and Remediation.sql
Last active July 12, 2021 13:41
TempDB Sizing Check and Remediation script
/*
-----------------------------------
TempDB Sizing Check and Remediation
-----------------------------------
Author: Eitan Blumin | https://www.eitanblumin.com
Description:
This script makes sure that all TempDB files are equally sized, based on a calculation that takes into consideration
the disk volume where the TempDB files are located.
This check only works when TempDB files are isolated from other databases and exist on their own dedicated volume.
@EitanBlumin
EitanBlumin / Foreign Keys Without Corresponding Indexes.sql
Last active November 16, 2021 09:05
Generate Index Creation script for FK without indexes
/*========================================================================================================================
-- Description: This query retrieves all the foreign keys in spesific DB that dont have corresponding indexes.
-- Scope: Database
-- Author: Guy Glantser | https://www.madeiradata.com
-- Create Date: 08/04/2012
-- Type: Query Plug&play
-- Last Updated On: 08/04/2012
-- Notes:
=========================================================================================================================*/