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
@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()]
@petervandivier
petervandivier / !README.md
Last active July 7, 2022 16:07
Pester PS Class

I'm attempting (and failing) to run a data-driven Pester v5 test over a PS Class. In the Tests/ directory are the 3 (currently failing) implemetations.

@petervandivier
petervandivier / sql2019_showplanxml.xsd
Created May 26, 2022 13:56
schemas.microsoft.com_sqlserver_2004_07_showplan_sql2019_showplanxml.xsd
<xsd:schema xmlns:shp="http://schemas.microsoft.com/sqlserver/2004/07/showplan"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://schemas.microsoft.com/sqlserver/2004/07/showplan" elementFormDefault="qualified"
attributeFormDefault="unqualified" version="1.539" blockDefault="#all">
<xsd:annotation>
<xsd:documentation> The following schema for Microsoft SQL Server describes output from the showplan
functionality in XML format. Microsoft does not make any representation or warranty regarding the schema or
any product or item developed based on the schema. The schema is provided to you on an AS IS basis.
Microsoft disclaims all express, implied and statutory warranties, including but not limited to the implied
warranties of merchantability, fitness for a particular purpose, and freedom from infringement. Without