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
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.
Write-Warning "This code is not meant to be run sequentially, run it in sections following comment instructions"
exit
<##############################################################################
create transfer file
##############################################################################>
$FilePath = "C:\temp\transfer_file.txt"
$DesiredFileSizeKB = 1024 * 7 # 7 MB
@TheRockStarDBA
TheRockStarDBA / dbo.MyPatchLevel.sql
Last active September 9, 2016 18:35 — forked from billinkc/dbo.MyPatchLevel.sql
Possibly handy views for identifying SQL Server patches and then what is my patch level - how long since patched, etc. Covers 2005 to current
CREATE VIEW dbo.MyPatchLevel
AS
WITH MostRecentBuild AS
(
SELECT
SRC.Build
, SRC.[Release Date]
, SRC.SimpleVersion
, SRC.[KB / Description]
FROM
@TheRockStarDBA
TheRockStarDBA / springer-free-maths-books.md
Created December 29, 2015 15:30 — forked from bishboria/springer-free-maths-books.md
Springer have made a bunch of books available for free, here are the direct links
@TheRockStarDBA
TheRockStarDBA / ColumnstoreReorg.sql
Created March 28, 2016 21:37 — forked from feaselkl/ColumnstoreReorg.sql
Run this to get a list of columnstore index partitions to determine which should be reorganized. This script also generates index reorg statements which could be run.
-------------------------------------------------------------------
-- Script Name: ColumnstoreReorg.sql
--
-- Desc: Run this to get a list of columnstore index partitions
-- to determine which should be reorganized. The script also
-- generates index reorg statements which could be run.
--
-- Notes: SQL Server 2016 is REQUIRED. SQL Server 2016 changed
-- what index reorganization does to columnstore indexes,
-- and this script takes advantage of those changes.
-- See http://dba.stackexchange.com/questions/136235/group-daily-schedule-into-start-date-end-date-intervals-with-the-list-of-week/136571?noredirect=1#comment257069_136571
/*****************************************************************
DATA: Create sample data
*****************************************************************/
IF OBJECT_ID('tempdb..#src') IS NOT NULL
DROP TABLE #src
CREATE TABLE #src (ID int PRIMARY KEY, ContractID int, dt date, dowChar char(3), dowInt int);
<#
.SYNOPSIS
Get-SqlErrorLog is designed to quickly retrieve data from SQL Server error logs, negating the slowness of SSMS and awkwardness of manually crawling files.
.DESCRIPTION
Get-SqlErrorLog is designed to quickly retrieve data from SQL Server error logs, negating the slowness of SSMS and awkwardness of manually crawling files.
It is designed to be quite light in it's process, and should be quick (loading SQLPLS being the exception.
@TheRockStarDBA
TheRockStarDBA / VeryBasicAGPerf.sql
Created April 29, 2016 22:13 — forked from sirsql/VeryBasicAGPerf.sql
Just provides very basic info around how your AG is doing. Run on primary to see sending stats, run on secondary to see receiving stats (and see how far behind things are)
SELECT db_name(database_id ), database_id as di,
datediff(minute, last_sent_time, last_received_time) AS SendRec,
datediff(minute, last_received_time, last_redone_time) AS RecRedo,
--datediff(minute, last_sent_time, last_redone_time) as MinsRedo,
case when redo_queue_size = 0 then 0
when redo_rate = 0 then 0
else cast(redo_queue_size / (redo_rate*1.0) as numeric(12,3)) end as MinToRedo,
case when log_send_queue_size = 0 then 0
when log_send_rate = 0 then 0
else cast(log_send_queue_size / (log_send_rate*1.0) as numeric(12,3))
@TheRockStarDBA
TheRockStarDBA / Build.xml
Created May 3, 2016 19:31 — forked from NickCraver/Build.xml
Stack Overflow Build Reference Docs
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="PrepareStaticContent" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<!-- Passed in Parameters -->
<configuration></configuration>
<workingDir></workingDir>
<buildNumber></buildNumber>
<buildViews>false</buildViews>
<minifyJs>true</minifyJs>
<TargetsDirectory></TargetsDirectory>