### Execute sp_BlitzFirst for Monitoring Setup Source: https://github.com/brentozarultd/sql-server-first-responder-kit/wiki/Install-first-responder-on-SQL-Server Use this script to configure sp_BlitzFirst to create and populate monitoring tables in the specified database. Set the retention period for the data. ```sql use DBATools; EXEC sp_BlitzFirst @OutputDatabaseName = 'DBAtools', @OutputSchemaName = 'dbo', @OutputTableName = 'BlitzFirst', @OutputTableNameFileStats = 'BlitzFirst_FileStats', @OutputTableNamePerfmonStats = 'BlitzFirst_PerfmonStats', @OutputTableNameWaitStats = 'BlitzFirst_WaitStats', @OutputTableNameBlitzCache = 'BlitzCache', @OutputTableNameBlitzWho = 'BlitzWho', @OutputTableRetentionDays = 18; ``` -------------------------------- ### Execute sp_BlitzCache with OpenAI Defaults Source: https://github.com/brentozarultd/sql-server-first-responder-kit/blob/dev/Documentation/Using_AI.md Run sp_BlitzCache with the @AI parameter enabled to get AI-powered query tuning recommendations. This example uses the default OpenAI gpt-5-nano model. ```sql EXEC sp_BlitzCache @Top = 1, @AI = 1; ``` -------------------------------- ### Typical Workflow: Generate and Execute Comparison Script Source: https://github.com/brentozarultd/sql-server-first-responder-kit/blob/dev/README.md This is the most common workflow. First, run the command on the server experiencing slowness to get a comparison script. Then, execute that script on another server to perform the diff. ```tsql /* Step 1 — on the server where you noticed the slowness */ EXEC dbo.sp_BlitzPlanCompare @QueryPlanHash = 0xABCD1234567890EF; ``` -------------------------------- ### Linked Server Comparison Source: https://github.com/brentozarultd/sql-server-first-responder-kit/blob/dev/README.md Execute sp_BlitzPlanCompare across a linked server. This requires RPC OUT to be enabled and the procedure installed on both servers. The comparison uses the stable query hash. ```tsql /* Needs RPC OUT and the proc installed on both sides. */ EXEC dbo.sp_BlitzPlanCompare @QueryPlanHash = 0xABCD1234567890EF, @LinkedServer = 'OtherSrv'; ``` -------------------------------- ### Execute sp_BlitzCache Using Configuration Table (Default Model) Source: https://github.com/brentozarultd/sql-server-first-responder-kit/blob/dev/Documentation/Using_AI.md Execute sp_BlitzCache with AI enabled, referencing a configuration table to determine the AI model to use. This example uses the default model specified in the table. ```sql /* Use the default model from your config table */ EXEC sp_BlitzCache @Top = 1, @AI = 1, @AIConfigTable = 'master.dbo.Blitz_AI_Providers'; ``` -------------------------------- ### Insert Deadlock Tuning Prompt for sp_BlitzCache Source: https://github.com/brentozarultd/sql-server-first-responder-kit/blob/dev/Documentation/Using_AI.md Adds a prompt for sp_BlitzCache specifically for addressing deadlocks and blocking issues. This prompt guides the AI to focus on query and index changes to reduce contention. ```sql INSERT INTO dbo.Blitz_AI_Prompts (Prompt_Nickname, Default_Prompt, AI_System_Prompt) VALUES ('sp_BlitzCache Deadlock Tuning', 0, 'You are a very senior database developer working with Microsoft SQL Server and Azure SQL DB. You focus on real-world, actionable advice that will make a big difference, quickly. You value everyone''s time, and while you are friendly and courteous, you do not waste time with pleasantries or emoji because you work in a fast-paced corporate environment. You have a query that is experiencing deadlocks and blocking. You have been tasked with making serious improvements to it, quickly. You are not allowed to change server-level or database-level settings nor make frivolous suggestions like updating statistics. Instead, you need to focus on query changes or index changes that will reduce blocking and deadlocks. Do not offer followup options: the customer can only contact you once, so include all necessary information, tasks, and scripts in your initial reply. Render your output in Markdown, as it will be shown in plain text to the customer.'); ``` -------------------------------- ### Configure sp_Blitz to Skip Specific Checks or Databases Source: https://github.com/brentozarultd/sql-server-first-responder-kit/blob/dev/README.md This example shows how to create and populate a table to define which checks or databases sp_Blitz should ignore. This allows for customized health checks. ```tsql CREATE TABLE dbo.BlitzChecksToSkip ( ServerName NVARCHAR(128), DatabaseName NVARCHAR(128), CheckID INT ); GO INSERT INTO dbo.BlitzChecksToSkip (ServerName, DatabaseName, CheckID) VALUES (NULL, 'SalesDB', 50) sp_Blitz @SkipChecksDatabase = 'DBAtools', @SkipChecksSchema = 'dbo', @SkipChecksTable = 'BlitzChecksToSkip'; ``` -------------------------------- ### Execute sp_BlitzPlanCompare by Query Hash Source: https://github.com/brentozarultd/sql-server-first-responder-kit/blob/dev/README.md Use this when you know the query hash, which is often sufficient to identify the relevant plan. ```tsql EXEC dbo.sp_BlitzPlanCompare @QueryHash = 0x1234567890ABCDEF; ``` -------------------------------- ### Execute sp_BlitzCache with Custom Prompt Source: https://github.com/brentozarultd/sql-server-first-responder-kit/blob/dev/Documentation/Using_AI.md Demonstrates how to call sp_BlitzCache using a specific custom prompt defined in the AI_Prompts table. This allows for targeted analysis based on the chosen prompt. ```sql EXEC sp_BlitzCache @Top = 1, @AI = 2, @AIPromptConfigTable = 'master.dbo.Blitz_AI_Prompts', @AIPrompt = 'sp_BlitzCache Modernize'; ``` -------------------------------- ### Identify specific statement in multi-statement proc Source: https://github.com/brentozarultd/sql-server-first-responder-kit/blob/dev/README.md When dealing with multi-statement stored procedures, use this to get a disambiguation result set. Copy a 'query_plan_hash_text' value to re-run the comparison with the specific statement's plan. ```tsql EXEC dbo.sp_BlitzPlanCompare @StoredProcName = 'dbo.big_proc'; /* -> returns one row per cached plan with set_options + query_text_snippet. Copy a query_plan_hash_text value and re-run with @QueryPlanHash. */ ``` -------------------------------- ### Execute sp_BlitzCache Using Configuration Table (Specific Model and Prompt) Source: https://github.com/brentozarultd/sql-server-first-responder-kit/blob/dev/Documentation/Using_AI.md Execute sp_BlitzCache with AI enabled, specifying both a particular AI model and a prompt template from configuration tables. This provides fine-grained control over AI behavior. ```sql /* Use a specific model AND prompt */ EXEC sp_BlitzCache @Top = 1, @AI = 1, @AIConfigTable = 'master.dbo.Blitz_AI_Providers', @AIModel = 'ChatGPT Slow'; @AIPromptConfigTable = 'master.dbo.Blitz_AI_Prompts', @AIPrompt = 'sp_BlitzCache Deadlock Tuning'; ``` -------------------------------- ### Execute sp_BlitzPlanCompare by Query Plan Hash Source: https://github.com/brentozarultd/sql-server-first-responder-kit/blob/dev/README.md Use this when you know the exact query plan hash for the execution plan you want to analyze. ```tsql EXEC dbo.sp_BlitzPlanCompare @QueryPlanHash = 0xABCD1234567890EF; ``` -------------------------------- ### Create Master Key for Database Credentials Source: https://github.com/brentozarultd/sql-server-first-responder-kit/blob/dev/Documentation/Using_AI.md Before creating database-scoped credentials, ensure a master key is created in the database. Replace 'YourDatabase' and 'YourStrongPassword!' with your specific details. ```sql USE YourDatabase; CREATE MASTER KEY ENCRYPTION BY PASSWORD = 'YourStrongPassword!'; ``` -------------------------------- ### Insert Index Tuning Prompt for sp_BlitzCache Source: https://github.com/brentozarultd/sql-server-first-responder-kit/blob/dev/Documentation/Using_AI.md Adds a specific prompt for sp_BlitzCache focused solely on index tuning recommendations. This prompt restricts suggestions to index changes only. ```sql INSERT INTO dbo.Blitz_AI_Prompts (Prompt_Nickname, Default_Prompt, AI_System_Prompt) VALUES ('sp_BlitzCache Index Tuning', 0, 'You are a very senior database developer working with Microsoft SQL Server and Azure SQL DB. You focus on real-world, actionable advice that will make a big difference, quickly. You value everyone''s time, and while you are friendly and courteous, you do not waste time with pleasantries or emoji because you work in a fast-paced corporate environment. You have a query that isn''t performing to end user expectations. You have been tasked with making serious improvements to it, quickly, but you are only allowed to make index changes. You are not allowed to make changes to the query, server-level settings, database settings, etc. Do not offer followup options: the customer can only contact you once, so include all necessary information, tasks, and scripts in your initial reply. Render your output in Markdown, as it will be shown in plain text to the customer.'); ``` -------------------------------- ### Generate Query Tuning Prompts with sp_BlitzCache Source: https://github.com/brentozarultd/sql-server-first-responder-kit/blob/dev/Documentation/Using_AI.md Use @AI = 2 with sp_BlitzCache to generate a prompt containing query text, execution plan, and performance metrics. This prompt can be copied and pasted into AI tools like ChatGPT or Gemini. ```sql EXEC sp_BlitzCache @Top = 1, @AI = 2; ``` -------------------------------- ### Show Kill Recommendations by CPU Usage Source: https://github.com/brentozarultd/sql-server-first-responder-kit/blob/dev/README.md Identify sessions that would be recommended for killing based on a specific login name, sorted by their CPU consumption. This is a read-only operation. ```tsql EXEC sp_kill @LoginName = 'DOMAIN\TroublesomeUser', @OrderBy = 'cpu'; ``` -------------------------------- ### Insert OpenAI AI Provider Configurations Source: https://github.com/brentozarultd/sql-server-first-responder-kit/blob/dev/Documentation/Using_AI.md Populate the AI providers table with configurations for OpenAI models. Includes settings for a fast, cheap model and a higher quality, slower, more expensive model. ```sql /* OpenAI - fast, cheap model, default: */ INSERT INTO dbo.Blitz_AI_Providers (Model_Nickname, AI_Model, AI_URL, AI_Database_Scoped_Credential_Name, Timeout_Seconds, Default_Model) VALUES (N'ChatGPT Fast', N'gpt-5-nano', N'https://api.openai.com/v1/chat/completions', N'https://api.openai.com/', 30, 1); /* OpenAI - highest quality, slowest, most expensive model: */ INSERT INTO dbo.Blitz_AI_Providers (Model_Nickname, AI_Model, AI_URL, AI_Database_Scoped_Credential_Name, Timeout_Seconds, Default_Model) VALUES (N'ChatGPT Slow', N'gpt-5.4', N'https://api.openai.com/v1/chat/completions', N'https://api.openai.com/', 230, 0); ``` -------------------------------- ### Execute sp_Blitz for Result Table Creation Source: https://github.com/brentozarultd/sql-server-first-responder-kit/wiki/Install-first-responder-on-SQL-Server Run this command in the DBATools database to create the necessary tables for storing the results of the sp_Blitz stored procedure. ```sql use DBATools; exec sp_Blitz @OutputDatabaseName = 'DBAtools', @OutputSchemaName = 'dbo', @OutputTableName = 'BlitzResults' ``` -------------------------------- ### Execute sp_BlitzCache Using Configuration Table (Specific Model) Source: https://github.com/brentozarultd/sql-server-first-responder-kit/blob/dev/Documentation/Using_AI.md Execute sp_BlitzCache with AI enabled, specifying a particular AI model from the configuration table. This allows overriding the default model for a specific execution. ```sql /* Use a specific model from your config table */ EXEC sp_BlitzCache @Top = 1, @AI = 1, @AIConfigTable = 'master.dbo.Blitz_AI_Providers', @AIModel = 'ChatGPT Slow'; ``` -------------------------------- ### Generate Index Advice Prompts with sp_BlitzIndex Source: https://github.com/brentozarultd/sql-server-first-responder-kit/blob/dev/Documentation/Using_AI.md Use @AI = 2 with sp_BlitzIndex in single-table mode to generate a prompt with detailed index and table information. This prompt includes existing indexes, missing index suggestions, column data types, and foreign key details. ```sql EXEC sp_BlitzIndex @DatabaseName = 'YourDatabase', @SchemaName = 'dbo', @TableName = 'YourTable', @AI = 2; ``` -------------------------------- ### Execute sp_BlitzIndex with Default AI Model Source: https://github.com/brentozarultd/sql-server-first-responder-kit/blob/dev/Documentation/Using_AI.md Run sp_BlitzIndex with AI enabled using the default ChatGPT model. Ensure you specify the database, schema, and table name. ```sql EXEC sp_BlitzIndex @DatabaseName = 'YourDatabase', @SchemaName = 'dbo', @TableName = 'YourTable', @AI = 1; ``` -------------------------------- ### Execute sp_Blitz and Save Output to a Table Source: https://github.com/brentozarultd/sql-server-first-responder-kit/blob/dev/README.md This snippet demonstrates how to run sp_Blitz and direct its output to a specified table for historical tracking. The target table will be created if it doesn't exist. ```tsql EXEC sp_Blitz @OutputDatabaseName = 'DBAtools', @OutputSchemaName = 'dbo', @OutputTableName = 'BlitzResults'; ``` -------------------------------- ### Create Custom AI Prompt Table Source: https://github.com/brentozarultd/sql-server-first-responder-kit/blob/dev/Documentation/Using_AI.md Define the schema for storing custom AI prompts. This table holds different prompt variations with nicknames and system prompt text. ```sql CREATE TABLE dbo.Blitz_AI_Prompts ( Id INT IDENTITY(1,1) PRIMARY KEY CLUSTERED, Prompt_Nickname NVARCHAR(200), AI_System_Prompt NVARCHAR(4000), Default_Prompt BIT DEFAULT 0 ); ``` -------------------------------- ### Execute sp_BlitzIndex with Custom AI Configuration Source: https://github.com/brentozarultd/sql-server-first-responder-kit/blob/dev/Documentation/Using_AI.md Execute sp_BlitzIndex with AI enabled, specifying custom configuration tables for providers and prompts. This allows for fine-grained control over the AI model and prompt used. ```sql EXEC sp_BlitzIndex @DatabaseName = 'YourDatabase', @SchemaName = 'dbo', @TableName = 'YourTable', @AI = 1, @AIConfigTable = 'master.dbo.Blitz_AI_Providers', @AIModel = 'ChatGPT Slow' @AIPromptConfigTable = 'master.dbo.Blitz_AI_Prompts', @AIPrompt = 'sp_BlitzIndex OLTP'; /* Or whatever custom prompt you inserted */ ``` -------------------------------- ### Execute sp_BlitzCache with Google Gemini Source: https://github.com/brentozarultd/sql-server-first-responder-kit/blob/dev/Documentation/Using_AI.md Run sp_BlitzCache with AI enabled, explicitly specifying the Google Gemini model and URL. This allows for using Gemini instead of the default OpenAI. ```sql EXEC sp_BlitzCache @Top = 1, @AI = 1, @AIModel = N'gemini-2.5-flash', @AIURL = N'https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:generateContent'; ``` -------------------------------- ### Push Backup History to Listener Source: https://github.com/brentozarultd/sql-server-first-responder-kit/blob/dev/README.md Use this snippet to push backup data from msdb to a centralized location. Ensure the linked server is configured correctly for the specified listener name. ```tsql EXEC sp_BlitzBackups @PushBackupHistoryToListener = 1, @WriteBackupsToListenerName = 'AG_LISTENER_NAME', @WriteBackupsToDatabaseName = 'FAKE_MSDB_NAME', @WriteBackupsLastHours = -24 ``` -------------------------------- ### Insert Default sp_BlitzCache Prompt Source: https://github.com/brentozarultd/sql-server-first-responder-kit/blob/dev/Documentation/Using_AI.md Adds the default system prompt for sp_BlitzCache to the custom prompts table. This prompt focuses on query tuning without server-level changes. ```sql INSERT INTO dbo.Blitz_AI_Prompts (Prompt_Nickname, Default_Prompt, AI_System_Prompt) VALUES ('sp_BlitzCache Default', 1, 'You are a very senior database developer working with Microsoft SQL Server and Azure SQL DB. You focus on real-world, actionable advice that will make a big difference, quickly. You value everyone''s time, and while you are friendly and courteous, you do not waste time with pleasantries or emoji because you work in a fast-paced corporate environment. You have a query that isn''t performing to end user expectations. You have been tasked with making serious improvements to it, quickly. You are not allowed to change server-level settings or make frivolous suggestions like updating statistics. Instead, you need to focus on query changes or index changes. Do not offer followup options: the customer can only contact you once, so include all necessary information, tasks, and scripts in your initial reply. Render your output in Markdown, as it will be shown in plain text to the customer.'); ``` -------------------------------- ### Insert Modernization Prompt for sp_BlitzCache Source: https://github.com/brentozarultd/sql-server-first-responder-kit/blob/dev/Documentation/Using_AI.md Adds a prompt for sp_BlitzCache focused on modernizing legacy queries. This prompt encourages the AI to leverage new SQL Server features while avoiding server or index modifications. ```sql INSERT INTO dbo.Blitz_AI_Prompts (Prompt_Nickname, Default_Prompt, AI_System_Prompt) VALUES ('sp_BlitzCache Modernize', 0, 'You are a very senior database developer working with Microsoft SQL Server and Azure SQL DB. You focus on real-world, actionable advice that will make a big difference, quickly. You value everyone''s time, and while you are friendly and courteous, you do not waste time with pleasantries or emoji because you work in a fast-paced corporate environment. You have been given a legacy query that needs to be modernized. Our goals are to make the query run faster, make it easier to understand, easier to maintain, and to take advantage of new features up to and including SQL Server 2025. You have been tasked with making serious improvements to it, quickly, without touching server-level settings, database-level settings, indexes, or statistics. Do not offer followup options: the customer can only contact you once, so include all necessary information, tasks, and scripts in your initial reply. Render your output in Markdown, as it will be shown in plain text to the customer.'); ``` -------------------------------- ### Execute sp_BlitzPlanCompare by Stored Procedure Name Source: https://github.com/brentozarultd/sql-server-first-responder-kit/blob/dev/README.md Use this to analyze plans for a specific stored procedure within a database. The procedure may return multiple plans if it's multi-statement. ```tsql EXEC dbo.sp_BlitzPlanCompare @StoredProcName = 'dbo.usp_GetTopPosts', @DatabaseName = 'StackOverflow'; ```