Skip to content

Instantly share code, notes, and snippets.

View JosiahSiegel's full-sized avatar
🌌

Josiah Siegel JosiahSiegel

🌌
View GitHub Profile
@JosiahSiegel
JosiahSiegel / ddm_auto.sql
Last active September 10, 2024 17:01
Dynamic Data Masking Automation
/*
EXECUTE AS USER = 'non-admin-user';
SELECT *
FROM masked_table
REVERT;
*/
DECLARE
@JosiahSiegel
JosiahSiegel / sql_server_quick_analysis.sql
Last active November 5, 2025 23:04
SQL Server Quick Analysis
-- Optimized Session Monitor with Query Plans (Works on both Azure SQL DB and SQL Server VM)
-- Using READ UNCOMMITTED for minimal blocking during monitoring
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
GO
;WITH SessionMetrics AS (
SELECT
er.session_id AS sid,
er.blocking_session_id AS blocked_by,
-- Accurate issue detection based on Microsoft documentation
STUFF(
@JosiahSiegel
JosiahSiegel / elastic_agent_jobs.sql
Last active October 10, 2025 18:47
Elastic Agent Jobs
-- Elastic Agent Jobs
-- Official doc: https://learn.microsoft.com/en-us/azure/azure-sql/database/elastic-jobs-tsql-create-manage?view=azuresql
-- Unofficial doc: https://sqlkitty.com/elastic-jobs-azure-sql-db/
-- Add target group
EXEC jobs.sp_add_target_group 'AzureSQLDBs';
-- Add single database (or server/elastic pool) to target group
EXEC jobs.sp_add_target_group_member
@target_group_name = 'AzureSQLDBs',
DECLARE @object_id INT = OBJECT_ID('dbo.YourTable');
DECLARE @db_id INT = DB_ID();
DECLARE @index_id INT;
DECLARE @index_name NVARCHAR(128);
DROP TABLE IF EXISTS #IndexStats
SELECT TOP 0 *
INTO #IndexStats
FROM sys.dm_db_index_physical_stats(@db_id, NULL, NULL, NULL, 'LIMITED');
@JosiahSiegel
JosiahSiegel / ado_items.wiql
Last active May 17, 2024 14:39
Azure DevOps (ADO) Assignments - Best Query (wiql)
SELECT
[System.State],
[System.Id],
[System.Title],
[System.IterationLevel2],
[Microsoft.VSTS.Common.ClosedDate]
FROM workitemLinks
WHERE
(
[Source].[System.TeamProject] = @project
@JosiahSiegel
JosiahSiegel / ssh_key_auth.md
Last active May 15, 2024 15:20
SSH Key Authentication

SSH Key Authentication

Generate key pair

ssh-keygen -t ed25519 -b 4096

Restrict private key access

@JosiahSiegel
JosiahSiegel / migrate_data.md
Last active May 3, 2024 14:28
PostgreSQL / Citus Migrate Production Data
@JosiahSiegel
JosiahSiegel / azure_vm_ssh.md
Created February 2, 2024 14:33
Azure VM SSH with AAD (Entra)

Login and install ssh extension

az login
az extension add --name ssh

Create 24 hour auth in ssh config

az ssh config --resource-group myResourceGroup --name myVm --file ./sshconfig
@JosiahSiegel
JosiahSiegel / choco.config
Last active August 14, 2023 17:51
Chocolatey developer environment
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="7zip.install" />
<package id="adobereader" />
<package id="azure-data-studio" />
<package id="chocolatey" />
<package id="chocolatey-compatibility.extension" />
<package id="chocolatey-core.extension" />
<package id="chocolatey-dotnetfx.extension" />
<package id="chocolateygui" />
@JosiahSiegel
JosiahSiegel / insert_json_array.sql
Last active June 16, 2023 18:33
Merge JSON array into SQL table
/*
CREATE TABLE [dbo].[test_jsonmerge](
[id] [int] NOT NULL,
[people_id] [varchar](50) NOT NULL,
[last_name] [varchar](50) NULL,
[sms_status] [varchar](50) NULL,
CONSTRAINT [PK_test_jsonmerge] PRIMARY KEY CLUSTERED
(
[id] ASC,
[people_id] ASC