This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| sp_whoisactive @get_plans = 1; | |
| --http://whoisactive.com/docs/06_options/ | |
| @filter sysname = '' | |
| @filter_type VARCHAR(10) = 'session' | |
| @not_filter sysname = '' | |
| @not_filter_type VARCHAR(10) = 'session' | |
| @show_own_spid BIT = 0 | |
| @show_system_spids BIT = 0 | |
| @show_sleeping_spids TINYINT = 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Enter-PSSession SERVERNAME1 | |
| Get-Volume |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| --Create a test database. | |
| CREATE DATABASE myDatabase | |
| --Change database context. | |
| USE myDatabase | |
| GO | |
| --Create a test table. | |
| DROP TABLE IF EXISTS myTable | |
| CREATE TABLE myTable ( firstname VARCHAR(25), surname VARCHAR(25), email VARCHAR(50) ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| --Kill a SPID | |
| --It's always a risk to kill anything - Rollbacks may be painful. | |
| KILL 60; | |
| GO | |
| --KILL WITH STATUSONLY does not KILL- Shows the current progress of the rollback.*/ | |
| KILL 60 WITH STATUSONLY; | |
| GO |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| --Kill all user SPIDs | |
| USE master | |
| GO | |
| DECLARE @kill VARCHAR(8000) = ''; | |
| SELECT @kill = @kill + 'kill ' + CONVERT(VARCHAR(5), spid) + ';' | |
| FROM master..sysprocesses | |
| WHERE dbid = db_id('DATABASE123') | |
| PRINT @kill | |
| --EXEC(@kill) --uncomment when ready |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| --Create a sp_WhoIsActive logging table. | |
| /*Change MYDATABASE1 & MYLOGGINGTABLE below*/ | |
| DECLARE @sql VARCHAR(MAX) | |
| EXEC sp_WhoIsActive | |
| @get_plans = 1, | |
| @get_transaction_info = 1, | |
| @return_schema = 1, | |
| @schema = @sql OUTPUT | |
| SET @sql = REPLACE(@sql, '<table_name>', '[DBTools].[dbo].[WhoIsActiveGather]') | |
| PRINT (@sql) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| --Log activity into table. | |
| DECLARE @destination_table VARCHAR(4000) = '[DBTools].[dbo].[WhoIsActiveGather]' | |
| EXEC [DBTools].[dbo].[sp_WhoIsActive] | |
| @get_plans = 1, | |
| @get_transaction_info = 1, | |
| @destination_table = @destination_table; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| --Delete from logging table. | |
| DECLARE @retention INT = 14; | |
| DECLARE @retention_calc DATETIME = DATEADD(DAY, -@retention, GETDATE()) | |
| --PRINT @retention_calc | |
| DELETE | |
| FROM [DBTools].[dbo].[WhoIsActiveGather] | |
| WHERE [collection_time] < @retention_calc |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| --Create test database. | |
| CREATE DATABASE quick_test | |
| --Change query context. | |
| USE quick_test | |
| GO | |
| --Create a test table. | |
| CREATE TABLE test_insert (firstname VARCHAR(100), surname VARCHAR(100), created_date DATETIME) |