Skip to content

Instantly share code, notes, and snippets.

Avatar
🕵️‍♂️
Figuring it out

Eitan Blumin EitanBlumin

🕵️‍♂️
Figuring it out
View GitHub Profile
@EitanBlumin
EitanBlumin / SQLDatabaseYAMLBuildConfiguration.yml
Last active May 8, 2022 — forked from jpvelasco/SQLDatabaseYAMLBuildConfiguration.yml
SQL YAML Build Configuration for Azure Pipelines
View SQLDatabaseYAMLBuildConfiguration.yml
# SQL Database Project Build Configuration
trigger:
- master
pool:
vmImage: 'VS2017-Win2016'
variables:
solution: '**/*.sln'
@EitanBlumin
EitanBlumin / SQLSentry_Heartbeat_Monitoring.sql
Last active Apr 26, 2022
Example job command to implement self-monitoring for SQL Sentry monitoring service hearbeats
View SQLSentry_Heartbeat_Monitoring.sql
-- 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 / Low PAGE Compression Success Rates.sql
Last active Jan 16, 2022
Check for Low PAGE Compression Success Rates
View Low PAGE Compression Success Rates.sql
/*
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: */
@EitanBlumin
EitanBlumin / Hypothetical Indexes - Example Usage.sql
Created Dec 13, 2021
Hypothetical Indexes - Example Usage script
View Hypothetical Indexes - Example Usage.sql
/*** TODO: Replace [dbo].[MyTableName] with the name of your specific table ***/
-- step 1: CREATE
-- CREATE hypothetical indexes using the WITH STATISTICS_ONLY clause:
/* TODO: Replace with your own index definitions, but don't forget to use WITH STATISTICS_ONLY */
CREATE NONCLUSTERED INDEX [IX_Hypothetical]
@EitanBlumin
EitanBlumin / Move-SqlFilesAlwaysOn.ps1
Last active Oct 14, 2021
Moves files to a new location for a SQL Server database in an AlwaysOn Availability Group
View Move-SqlFilesAlwaysOn.ps1
# Copyright 2021 Eitan Blumin <@EitanBlumin, https://www.eitanblumin.com>
# while at Madeira Data Solutions <https://www.madeiradata.com>
#
# Licensed under the MIT License (the "License");
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR CO
@EitanBlumin
EitanBlumin / Table and Index High Unused Space.sql
Last active Sep 6, 2021
Checks for tables and indexes with a high percentage of allocated but unused space in all DBs, and generates remediation commands for it
View Table and Index High Unused Space.sql
DECLARE
@TopPerDB int = 50,
@MinimumRowCount int = 1000,
@MinimumUnusedSizeMB int = 1024,
@MinimumUnusedSpacePct int = 40,
@RebuildIndexOptions varchar(max) = 'ONLINE = ON, SORT_IN_TEMPDB = ON, MAXDOP = 1' -- , RESUMABLE = ON -- adjust as needed
SET NOCOUNT, ARITHABORT, XACT_ABORT ON;
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
DECLARE @command NVARCHAR(MAX);
@EitanBlumin
EitanBlumin / extended properties change tracking wrapper functions.sql
Last active Jul 24, 2021
Change Tracking Utility function and procedure to maintain last copied version
View extended properties change tracking wrapper functions.sql
CREATE FUNCTION dbo.ct_get_last_copied_version
(
@table_name sysname,
@target_identifier sysname = null -- optional parameter if you have multiple sync targets
)
RETURNS bigint
AS
BEGIN
RETURN ISNULL((SELECT convert(bigint, [value])
FROM sys.extended_properties
@EitanBlumin
EitanBlumin / extended properties global variable wrapper functions.sql
Created Jul 24, 2021
Function and stored procedure to implement Global Variables using Extended Properties
View extended properties global variable wrapper functions.sql
-- Function to Retrieve a global variable value
-- don't forget to convert to the correct data type
CREATE FUNCTION dbo.global_variable(@VariableName sysname)
RETURNS sql_variant
AS
BEGIN
RETURN (SELECT [value]
FROM sys.extended_properties
WHERE major_id = 0 AND minor_id = 0
AND [name] = @VariableName)
View Asynchronous Ledger Demo.sql
/*
Asynchronous Ledger Demo
========================
Author: Eitan Blumin | https://eitanblumin.com | https://madeiradata.com
Date: 2021-07-03
Description:
This script demonstrates a use case of a high-throughput table
which serves as a "hot-spot" for inserts and updates and queries.
This causes performance problems due to long lock chains, possible deadlocks,
and sometimes even worker thread starvation.
@EitanBlumin
EitanBlumin / Extended Properties as Database Global Variables.sql
Created Jun 14, 2021
Use Extended Properties as Database Global Variables
View Extended Properties as Database Global Variables.sql
/*
================================================
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