Skip to content

Instantly share code, notes, and snippets.

View petervandivier's full-sized avatar
🌶️
Why is it spicy?

Peter Vandivier petervandivier

🌶️
Why is it spicy?
View GitHub Profile
create or alter proc dbo.[BatchDelete<Table Name,,>]
@BatchSize smallint = 1000,
@RangeMax datetime = null,
@RangeMin datetime = null,
@DebugMode bit = 0
as
/***********************************************************************************************
-- DESCRIPTION: batch delete `dbo.[<Table Name,,>]` records older than retention policy.
-- Toggle @DebugMode for a summary of what *would be* deleted
-- but take no action (other than parameter validation).
function Get-AdxDashboardDefinition {
param (
[Parameter(Mandatory)]
[string]
$authorization,
[Parameter(Mandatory)]
[guid]
$DashboardGuid
@petervandivier
petervandivier / dba.se-347554.sql
Created August 21, 2025 17:40
Repro scripts for dba.se-347554.sql
-- Why does SQL Server Full Text Search (FTS) rank go down when match count goes up due to highly rare word
-- https://dba.stackexchange.com/q/347554/68127
use [master];
go
-- exec sp_WhoIsActive @show_system_spids = 1;
drop database if exists fts;
go
create database fts;
@petervandivier
petervandivier / ReadMe.md
Last active August 15, 2025 03:50
Tracing SQL Agent SMO
@petervandivier
petervandivier / demo-alter-trigger.sql
Created October 30, 2024 18:35
`columns_updated()` demo
use [master]
go
drop database if exists TriggerDemo;
go
create database TriggerDemo;
go
use TriggerDemo
go
create table dbo.foo (
id int not null primary key,
@petervandivier
petervandivier / cdc-__$update_mask-rubber-ducking.sql
Last active September 18, 2024 17:07
🦆 rubber ducking __$update_mask & __$operation for SQL Server CDC
/*
https://learn.microsoft.com/en-us/sql/relational-databases/system-tables/cdc-capture-instance-ct-transact-sql
wanted to check that for ins/del ops (2 & 1 respectively) that the full update bitmask always applies
it does:
- 0x0f bitmask on 4 cols
- 0x7f bitmask on 7 cols
- 0xFF bitmask on 8 cols
@petervandivier
petervandivier / make-nested-iif.sql
Last active September 9, 2024 16:21
SQL Server - nested `IIF` generator for `GREATEST` & `LEAST` workaround
drop table if exists
#row_comps,
#main,
#mid,
#end;
declare @indent varchar(50) = ' ';
-- manually input table & column names below
with cols as (

This is a markdown file.

graph TD;
    A(with a mermaid diagram)-->B;
    A-->C;
    B-->D;
    C-->D(embedded inside);
@petervandivier
petervandivier / parallel-begin-process-end.ps1
Created May 26, 2023 17:42
ValueFromPipeline processing in a function is serial unless you use a steppable pipeline
#Requires -PSEdition Core
# HT @santisq in powershell-slack
# https://powershell.slack.com/archives/C1RCWRDL4/p1685120926413089
function foo {
param(
[Parameter(Mandatory,ValueFromPipeline)]
[string]
$bar
function New-DateArray {
<#
.EXAMPLE
$days = New-DateArray '2021-01-01' '2021-02-01'
$days | % { $_.ToShortDateString() }
#>
[CmdletBinding()]
Param(
[Parameter()]