Skip to content

Instantly share code, notes, and snippets.

View tcartwright's full-sized avatar

Tim Cartwright tcartwright

  • Houston, Texas
View GitHub Profile
@tcartwright
tcartwright / Recreate Procs with Bad Set Options.sql
Created July 8, 2019 20:55
Recreate Procs with Bad Set Options
SET NOCOUNT ON
DECLARE @name sysname = N'',
@proc_definition NVARCHAR(MAX) = N'',
@proc_permissions NVARCHAR(MAX) = N'',
@crlf NVARCHAR(4) = CHAR(13) + CHAR(10),
@print_only BIT = 1
DECLARE @procs_tbl TABLE (
@tcartwright
tcartwright / ExtractDacPacFromDatabase.ps1
Created April 26, 2019 17:53
Extract dacpac from database
[CmdletBinding()]
param (
[Parameter(Mandatory=$true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
[string]
$server,
[Parameter(Mandatory=$true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
[string]
$dbname
)
@tcartwright
tcartwright / RemoveDiagramObjects.sql
Created April 25, 2019 17:12
Remove SQL Server Database diagram objects
-- REMOVE DATABASE DIAGRAMS OBJECTS FROM DB
-- ***WARNING*** ANY EXISTING DIAGRAMS WILL GET DELETED IF YOU RUN THIS ***WARNING***
IF OBJECT_ID('[dbo].[sp_upgraddiagrams]') IS NOT NULL BEGIN
DROP PROC [dbo].[sp_upgraddiagrams]
END
IF OBJECT_ID('[dbo].[sp_helpdiagrams]') IS NOT NULL BEGIN
DROP PROC [dbo].[sp_helpdiagrams]
END
@tcartwright
tcartwright / SQL Server Stored Procedures StackTrace - 2014 and prior.sql
Last active April 5, 2019 20:27
SQL Server Stored Procedures StackTrace - 2014 and prior
USE tempdb
GO
IF OBJECT_ID (N'GetErrorInfo') IS NOT NULL BEGIN
DROP PROCEDURE GetErrorInfo
END
GO
CREATE PROCEDURE GetErrorInfo (
@tcartwright
tcartwright / SQL Server Stored Procedures StackTrace - 2016.sql
Last active January 21, 2022 15:49
SQL Server Stored Procedures StackTrace - 2016
/*
Authors: Matthew Naul, Tim Cartwright
Purpose: to build a stack trace so that nested stored proces can be followed in the case of an exception.
*/
USE tempdb -- change this to the db of your choice. or put it master and make it a system stored proc
GO
IF OBJECT_ID('dbo.ErrorHandler') IS NULL BEGIN
EXEC ('CREATE PROCEDURE dbo.ErrorHandler AS BEGIN SELECT 1; END;');
@tcartwright
tcartwright / Who is active loop output.sql
Last active July 19, 2021 17:42
Runs who is active with a delay on a loop to capture differences
-- https://sqlworkbooks.com/2017/06/using-sp_whoisactive-with-temp-tables-to-limit-data-collected/
SET NOCOUNT ON
DECLARE @whoisactive_table VARCHAR(4000) = QUOTENAME ('##WhoIsActive_' + CAST(NEWID() as varchar(255)))
, @schema VARCHAR(4000)
, @dsql NVARCHAR(4000)
, @loop_cntr INT = 3
-- build the global temp table
EXEC sp_WhoIsActive
@tcartwright
tcartwright / GenerateRandomPassword2.sql
Last active September 18, 2025 14:41
SQL SERVER: Generate a random password (enhanced)
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE OR ALTER PROCEDURE [dbo].[GenerateRandomPwd] (
@password VARCHAR(512) OUTPUT,
@length INT = NULL, /* IF passed in then the password will be this exact length */
@lengthMin INT = 35, /* controls the min length of the password if @length is null */
@lengthMax INT = 50, /* controls the max length of the password if @length is null */
@tcartwright
tcartwright / GenerateRandomPassword.md
Last active March 26, 2025 16:11
SQL SERVER: Generate a random password
@tcartwright
tcartwright / Solarized.DarkScheme.vssettings
Created July 5, 2018 16:14
SSMS SOLARIZED DARK THEME
<UserSettings>
<ApplicationIdentity version="10.0"/>
<ToolsOptions>
<ToolsOptionsCategory name="Environment" RegisteredName="Environment"/>
</ToolsOptions>
<Category name="Environment_Group" RegisteredName="Environment_Group">
<Category name="Environment_FontsAndColors" Category="{1EDA5DD4-927A-43a7-810E-7FD247D0DA1D}" Package="{DA9FB551-C724-11d0-AE1F-00A0C90FFFC3}" RegisteredName="Environment_FontsAndColors" PackageName="Visual Studio Environment Package">
<PropertyValue name="Version">2</PropertyValue>
<FontsAndColors Version="2.0">
<Categories>
@tcartwright
tcartwright / VisualStudio.DarkScheme.vssettings
Created July 5, 2018 14:05
SSMS VISUAL STUDIO DARK THEME
<UserSettings>
<ApplicationIdentity version="10.0"/>
<ToolsOptions>
<ToolsOptionsCategory name="Environment" RegisteredName="Environment"/>
</ToolsOptions>
<Category name="Environment_Group" RegisteredName="Environment_Group">
<Category name="Environment_FontsAndColors" Category="{1EDA5DD4-927A-43a7-810E-7FD247D0DA1D}" Package="{DA9FB551-C724-11d0-AE1F-00A0C90FFFC3}" RegisteredName="Environment_FontsAndColors" PackageName="Visual Studio Environment Package">
<PropertyValue name="Version">2</PropertyValue>
<FontsAndColors Version="2.0">
<Categories>