Skip to content

Instantly share code, notes, and snippets.

View BrentOzar's full-sized avatar
❤️

Brent Ozar BrentOzar

❤️
View GitHub Profile
@BrentOzar
BrentOzar / sp_BlitzCache_AI_Migration.sql
Last active March 11, 2026 22:05
sp_BlitzCache 2025-12 AI config table structure migration to 2026 formats
/* Create the new table structures: */
CREATE TABLE dbo.Blitz_AI_Providers
(Id INT IDENTITY(1,1) PRIMARY KEY CLUSTERED,
AI_Model NVARCHAR(100) INDEX AI_Model,
AI_URL NVARCHAR(500),
AI_Database_Scoped_Credential_Name NVARCHAR(500),
AI_Parameters NVARCHAR(4000),
Timeout_Seconds TINYINT,
Context INT,
DefaultModel BIT DEFAULT 0);
@BrentOzar
BrentOzar / The-Ascending-Key-Problem.sql
Last active June 20, 2025 17:35
The Ascending Key Problem
/*
The Ascending Key Problem
Brent Ozar - https://www.BrentOzar.com/go/ascending
v1.4 - 2025-06-20
This demo requires:
* Any supported version of SQL Server
* A large Stack Overflow database: https://www.BrentOzar.com/go/querystack
@BrentOzar
BrentOzar / sp_predict_next_activity.sql
Created May 20, 2025 10:10
sp_predict_next_activity.sql
USE [master]
GO
/****** Object: StoredProcedure [sys].[sp_predict_next_activity] Script Date: 5/20/2025 3:04:06 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [sys].[sp_predict_next_activity] (
@retention_interval_days INT,
@BrentOzar
BrentOzar / sp_auto_tuning_update_workflow.sql
Created May 20, 2025 10:09
sp_auto_tuning_update_workflow.sql
USE [master]
GO
/****** Object: StoredProcedure [sys].[sp_auto_tuning_update_workflow] Script Date: 5/20/2025 3:02:31 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- null value means we do not want to update the corresponding column in internal table
ALTER PROCEDURE [sys].[sp_auto_tuning_update_workflow]
@BrentOzar
BrentOzar / sp_auto_tuning_update_index_recommendation.sql
Created May 20, 2025 10:08
sp_auto_tuning_update_index_recommendation.sql
USE [master]
GO
/****** Object: StoredProcedure [sys].[sp_auto_tuning_update_index_recommendation] Script Date: 5/20/2025 3:02:21 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- parameter value is null means we do not want to update the corresponding column in internal table
ALTER PROCEDURE [sys].[sp_auto_tuning_update_index_recommendation]
@BrentOzar
BrentOzar / sp_auto_tuning_update_create_index_workflow.sql
Created May 20, 2025 10:08
sp_auto_tuning_update_create_index_workflow.sql
USE [master]
GO
/****** Object: StoredProcedure [sys].[sp_auto_tuning_update_create_index_workflow] Script Date: 5/20/2025 3:02:08 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- null value means we do not want to update the corresponding column in internal table
ALTER PROCEDURE [sys].[sp_auto_tuning_update_create_index_workflow]
@BrentOzar
BrentOzar / sp_auto_tuning_publish_index_recommendation.sql
Created May 20, 2025 10:08
sp_auto_tuning_publish_index_recommendation.sql
USE [master]
GO
/****** Object: StoredProcedure [sys].[sp_auto_tuning_publish_index_recommendation] Script Date: 5/20/2025 3:01:58 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [sys].[sp_auto_tuning_publish_index_recommendation]
@index_type tinyint,
@BrentOzar
BrentOzar / sp_auto_tuning_index_recommendation_verification_report.sql
Created May 20, 2025 10:07
sp_auto_tuning_index_recommendation_verification_report.sql
USE [master]
GO
/****** Object: StoredProcedure [sys].[sp_auto_tuning_index_recommendation_verification_report] Script Date: 5/20/2025 3:01:40 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- The original SP of runner has the following two parameters
-- @verification_action_start_time DATETIME = NULL,
@BrentOzar
BrentOzar / sp_auto_tuning_create_workflow.sql
Created May 20, 2025 10:07
sp_auto_tuning_create_workflow.sql
USE [master]
GO
/****** Object: StoredProcedure [sys].[sp_auto_tuning_create_workflow] Script Date: 5/20/2025 3:01:29 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [sys].[sp_auto_tuning_create_workflow]
@execution_id uniqueidentifier,
@BrentOzar
BrentOzar / sp_auto_tuning_cleanup_index_recommendations.sql
Created May 20, 2025 10:06
sp_auto_tuning_cleanup_index_recommendations.sql
USE [master]
GO
/****** Object: StoredProcedure [sys].[sp_auto_tuning_cleanup_index_recommendations] Script Date: 5/20/2025 3:01:07 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [sys].[sp_auto_tuning_cleanup_index_recommendations]
(