Skip to content

Instantly share code, notes, and snippets.

View JosiahSiegel's full-sized avatar
🌌

Josiah Siegel JosiahSiegel

🌌
View GitHub Profile
@JosiahSiegel
JosiahSiegel / mysql_quick_analysis.sql
Created August 25, 2025 22:07
MySQL Quick Analysis
SELECT
ROW_NUMBER() OVER (ORDER BY section_order, priority) AS row_num,
section, metric, user_info, value, details, status,
query_text, problem_indicator
FROM (
-- SECTION 1: BLOCKING CHAINS AND LOCK ISSUES
(SELECT
1 as section_order, 1 as priority,
'BLOCKING' as section,
'Lock Chain' as metric,
@JosiahSiegel
JosiahSiegel / mysql_password_guide.md
Created August 18, 2025 13:24
MySQL Password Reset Guide for Azure MySQL Flexible Server

MySQL Password Reset Guide for Azure MySQL Flexible Server

Understanding One-Time Password Expiration and Mandatory Reset

This guide explains the complete process of forcing users to reset their password on first login using MySQL's password expiration feature. It addresses the seemingly counterintuitive requirement that users must login with their expired password to change it.


🔑 Why Users Must Login with an Expired Password

@JosiahSiegel
JosiahSiegel / identify_query_issues.sql
Last active July 24, 2025 21:06
Azure SQL Database: Identify Query Issues
DECLARE
@last_execution_time DATETIME = DATEADD(MINUTE, -60, GETUTCDATE())
;WITH FilteredRuntimeStats AS (
SELECT
rs.runtime_stats_id,
rs.plan_id,
rs.last_execution_time,
rs.count_executions,
rs.avg_cpu_time,
@JosiahSiegel
JosiahSiegel / logintracking.sql
Created May 13, 2025 13:26
SQL Server Event Session - LoginTracking
-- Create an Extended Events session to track login activities
CREATE EVENT SESSION [LoginTracking] ON SERVER
ADD EVENT sqlserver.login(
ACTION(
sqlserver.client_app_name, -- Application name
sqlserver.client_hostname, -- Client hostname
sqlserver.client_pid, -- Client process ID
sqlserver.database_name, -- Database name
sqlserver.nt_username, -- Windows username
sqlserver.server_principal_name, -- SQL Server login name
@JosiahSiegel
JosiahSiegel / .gitignore
Created April 28, 2025 14:58
sqlproj .gitignore
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
# User-specific files
*.suo
*.user
*.userosscache
*.sln.docstates
*.sqllite
@JosiahSiegel
JosiahSiegel / azure_sql_db_mfa.ps1
Created March 27, 2025 15:05
PowerShell Connect Azure SQL DB MFA
azureAccount = Connect-AzAccount
$azureToken = Get-AzAccessToken -ResourceUrl https://database.windows.net
$azureInstance = "MyServer.database.windows.net"
$azureDatabase = "MyDB"
$server = Connect-DbaInstance -SqlInstance $azureInstance -Database $azureDatabase -AccessToken $azureToken
Invoke-DbaQuery -SqlInstance $server -Query "SELECT @@VERSION" | Format-Table -AutoSize
@JosiahSiegel
JosiahSiegel / download_ms365_video.md
Created October 23, 2024 12:56
Download SharePoint/Stream/Teams Video

For those aiming to download videos from MS Teams meetings in which you participated but were not the Organizer, I managed to do so using yt-dlp and ffmpeg. The procedure is quite similar for both tools.

  • Open your Browser (I got it to work in Chrome, Edge and Firefox)
  • Login to portal.office.com
  • Go to where you can play the video you want to download, either via Sharepoint or Streams.
  • Hit F12
  • Go to the "Network" tab
  • Filter: videomanifest
  • Hit F5
  • Start playing the video
@JosiahSiegel
JosiahSiegel / fn_GetPartitionsForRange.sql
Created October 21, 2024 18:51
Get partition ranges or partitions of given range
-- =============================================
-- Author: Josiah Siegel
-- Create date: 2024-10-21
-- Description: Fetch partition ranges or partitions of given range
-- Example:
/*
-- Fetch partition ranges
select * from [fn_GetPartitionsForRange]('MyTable', DEFAULT, DEFAULT, DEFAULT)
-- Fetch partitions of given range
@JosiahSiegel
JosiahSiegel / force_hint.sql
Created October 17, 2024 20:58
Force hint on query in query store
-- get query id
SELECT
q.query_id,
qt.query_sql_text
FROM sys.query_store_query_text qt
INNER JOIN sys.query_store_query q ON
qt.query_text_id = q.query_text_id
WHERE query_sql_text like N'%select column from table%'
GO
@JosiahSiegel
JosiahSiegel / incremental_statistics.sql
Created October 11, 2024 14:59
Update statistics to incremental for partitioned tables
--ALTER DATABASE [MyDB] SET AUTO_CREATE_STATISTICS ON (INCREMENTAL = ON)
SELECT DISTINCT 'UPDATE STATISTICS ' + QUOTENAME(sc.name) + '.' + QUOTENAME(object_name(S.object_id)) + ' (' + QUOTENAME(s.name) + ') WITH INCREMENTAL = ON'
FROM sys.tables T
INNER JOIN sys.schemas sc ON t.schema_id = sc.schema_id
INNER JOIN sys.indexes I
ON T.object_id = I.object_id
INNER JOIN sys.data_spaces DS
ON I.data_space_id = DS.data_space_id
INNER JOIN sys.stats S
ON I.object_id = S.object_id