Skip to content

Instantly share code, notes, and snippets.

View TheRockStarDBA's full-sized avatar
🏠
Working from home

Kin Shah TheRockStarDBA

🏠
Working from home
View GitHub Profile
DECLARE @FileName NVARCHAR(4000)
SELECT @FileName =
LEFT(target_data.value('(EventFileTarget/File/@name)[1]','nvarchar(4000)') ,
CHARINDEX('system_health',target_data.value('(EventFileTarget/File/@name)[1]','nvarchar(4000)') )-1) + 'system_health*.xel'
FROM (
SELECT
CAST(target_data AS XML) target_data
@TheRockStarDBA
TheRockStarDBA / Cummulative IO stats for SQL Server
Created September 26, 2014 21:23
Cummulative IO stats for SQL Server
SELECT
QUOTENAME(DB_NAME(iovfs.[database_id])) [DatabaseName]
,iovfs.[file_id] [FileID]
,mf.[name] [LogicalName]
,mf.[type_desc] [FileType]
,SUM(iovfs.[num_of_bytes_read]) [Read_bytes]
,SUM(iovfs.[num_of_bytes_written]) [Written_bytes]
,SUM(iovfs.[num_of_bytes_read])/1048576 [Read_MiB]
,SUM(iovfs.[num_of_bytes_written])/1048576 [Written_MiB]
,SUM(iovfs.[num_of_reads]) [Read_Count]
@TheRockStarDBA
TheRockStarDBA / IndexBreakDownWithBuffered
Created September 26, 2014 21:31
Detailed Table and Index Breakdown With Buffered
/*
--http://jongurgul.com/blog/detailed-table-index-breakdown-buffered/
This script builds on the Detailed Table and Index script to further show the buffered metrics. This script will give you a comprehensive breakdown of your tables and indexes, which is shown with schema(s),table(s),index type(s),index size(s),row count(s) as well as the filegroup(s) and partition(s) information.
Also in this script I have included two columns called TippingPoint* which relate to the rough bounderies where a nonclustered index is no longer selective enough. I have applied the formula to the clustered index for ease. For more detail on an indexes tipping point please see Kimberly Tripp's article.
http://www.sqlskills.com/BLOGS/KIMBERLY/category/The-Tipping-Point.aspx
*/
SELECT
DB_NAME() [DatabaseName]
CREATE PROCEDURE sp_server_diag_event_parser
as
--SP_SERVER_DIAGNOSTICS Dynamic Parser for "events", v1.23
--You may use this at will, you may share it provided this header remains.
-- Copyright 2012 Michael Bourgon
-- Commercial use or sale prohibited without permission. Personal, Internal Company, or Private use is fine.
-- If you're just running this as your job as a DBA, enjoy.
-- Please feel free to share, and feel free to send corrections or enhancements - thebakingdba.blogspot.com
-- Thanks to Marc_S on Stackoverflow for the help on parsing XML.
-- Thanks to Stack Overflow for forcing me to come up with a good question - so I found the flawed derived table slowdown.
@TheRockStarDBA
TheRockStarDBA / AutoGrowth_Events
Last active May 5, 2019 06:54
AutogrowthSettings
/************************************************************************************************************************************************************************************************************************************
************************************************************************************************************************************************************************************************************************************
Author : Kin Shah
Purpose : Find Autogrowth Settings
Posted On : http://dba.stackexchange.com/a/82633/8783
http://dba.stackexchange.com/a/53917/8783
Disclaimer
The views expressed on my posts on this site are mine alone and do not reflect the views of my company. All posts of mine are provided "AS IS" with no warranties, and confers no rights.
@TheRockStarDBA
TheRockStarDBA / ChangeDatabaseCollation
Created April 10, 2015 19:24
Change Database Collation
/************************************************************************************************************************************************************************************************************************************
************************************************************************************************************************************************************************************************************************************
Author : Kin Shah
Bug Identified The incuded columns were not generated as a part of original script.
and Fixed : Modified the script to include the included columns.
Disclaimer
The views expressed on my posts on this site are mine alone and do not reflect the views of my company. All posts of mine are provided "AS IS" with no warranties, and confers no rights.
@TheRockStarDBA
TheRockStarDBA / WeakPasswordChecker.sql
Created April 15, 2015 14:08
Check Weak Passwords on a SQL Server instance using PWDCOMPARE()
/************************************************************************************************************************************************************************************************************************************
************************************************************************************************************************************************************************************************************************************
Author : Kin Shah
Purpose : Checks weak passwords on a sql server instance using PWDCOMPARE()
The list of weak passwords can be updated as per your needs.
Below is the source of WEAK passwords :
-- Ref: http://security.blogoverflow.com/category/password/
@TheRockStarDBA
TheRockStarDBA / sp_whoisactive.sql
Last active July 29, 2019 08:39
sp_whoisactive - from Adam Machanic
--- download it from http://sqlblog.com/files/folders/release/tags/who+is+active/default.aspx
EXEC sp_WhoIsActive
@filter = '',
@filter_type = 'session',
@not_filter = '',
@not_filter_type = 'session',
@show_own_spid = 0,
@show_system_spids = 0,
@show_sleeping_spids = 1,
@get_full_inner_text = 1,
@TheRockStarDBA
TheRockStarDBA / SearchAllTablesForString.sql
Created April 28, 2015 16:43
Search All tables for particular String or word
/*
- Search through tables to find specific text
- Written by Luis Chiriff (with help from SQL Server Central)
- luis.chiriff@gmail.com @ 24/11/2008 @ 11:54
*/
-- Variable Declaration
Declare @StringToFind VARCHAR(200), @Schema sysname, @Table sysname, @FullTable int, @NewMinID int, @NewMaxID int,
@SQLCommand VARCHAR(8000), @BaseSQLCommand varchar(8000), @Where VARCHAR(8000), @CountCheck varchar(8000) , @FieldTypes varchar(8000),
@TheRockStarDBA
TheRockStarDBA / Shrink_DB_In_Chunks.sql
Last active March 25, 2024 06:23
Shrink database in chunks - tsql
/*
This script is used to shrink a database file in
increments until it reaches a target free space limit.
Run this script in the database with the file to be shrunk.
1. Set @DBFileName to the name of database file to shrink.
2. Set @TargetFreeMB to the desired file free space in MB after shrink.
3. Set @ShrinkIncrementMB to the increment to shrink file by in MB
4. Run the script