Skip to content

Instantly share code, notes, and snippets.

View BrentOzar's full-sized avatar
❤️

Brent Ozar BrentOzar

❤️
View GitHub Profile
@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]
(
@BrentOzar
BrentOzar / ADR and RCSI Demo of Index Rebuilds.sql
Created January 9, 2025 16:11
ADR and RCSI Demo of Index Rebuilds
DROP DATABASE Test;
DROP DATABASE Test_ADR;
DROP DATABASE Test_ADR_RCSI;
DROP DATABASE Test_RCSI;
CREATE DATABASE Test;
CREATE DATABASE Test_ADR;
ALTER DATABASE Test_ADR SET ACCELERATED_DATABASE_RECOVERY = ON;
GO