Skip to content

Instantly share code, notes, and snippets.

@petesql
petesql / who_is_active_parameters.sql
Created January 22, 2018 23:26
who_is_active_parameters
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
@petesql
petesql / enter_ps_session_get_vol.ps1
Created January 23, 2018 20:39
enter_ps_session_get_vol
Enter-PSSession SERVERNAME1
Get-Volume
@petesql
petesql / who_is_active_tutorial_full.sql
Last active January 30, 2018 19:01
who_is_active_tutorial_full
--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) )
@petesql
petesql / kill_spids.sql
Created January 23, 2018 22:58
kill_spids
--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
@petesql
petesql / kill_all_user_spids.sql
Created January 23, 2018 23:11
kill_all_user_spids
--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
@petesql
petesql / related_posts_port_link_change.php
Created January 28, 2018 21:24
related_posts_port_link_change
@petesql
petesql / create_whoisactive_logging_table.sql
Last active January 30, 2018 18:47
create_whoisactive_logging_table
--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)
@petesql
petesql / log_whoisactive_into_table.sql
Created January 29, 2018 22:56
log_whoisactive_into_table
--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;
@petesql
petesql / delete_whoisactive_from_table
Created January 30, 2018 18:48
delete_whoisactive_from_table
--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
@petesql
petesql / test_insert.sql
Created February 18, 2018 17:56
test_insert
--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)