Skip to content

Instantly share code, notes, and snippets.

🕵
Figuring it out

Eitan Blumin EitanBlumin

🕵
Figuring it out
Block or report user

Report or block EitanBlumin

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@EitanBlumin
EitanBlumin / zendesk_open_ticket.ps1
Created Aug 22, 2019
Powershell script to open Zendesk support tickets, or add comment to an existing ticket (based on requester and subject). Useful for automatic monitoring and alerting systems.
View zendesk_open_ticket.ps1
param
(
[string] $Subject = "This is a test ticket from Powershell",
[string] $Body = "This is test description",
[string] $RequesterEmail = "dbmonitor@madeiradata.com",
[string] $SourceServer = "SqlDev2016",
[string] $SQLVersion = "2016",
[string] $SQLEdition = "Developer",
[string] $Priority = "low",
[string] $StartDate = "2018-04-17 23:30",
@EitanBlumin
EitanBlumin / Find Invalid Records by Check Constraint.sql
Last active Jul 31, 2019
Find the records which cause your not trusted check constraint to fail
View Find Invalid Records by Check Constraint.sql
/************** Find Invalid Records ***************
Author: Eitan Blumin
****************************************************/
DECLARE
@Constraint SYSNAME = 'CK_Name'
, @PrintOnly BIT = 0
DECLARE
@TableID INT,
@CheckDefinition NVARCHAR(MAX),
@EitanBlumin
EitanBlumin / Parse Vulnerability Assessment Scan Json File.sql
Last active Jul 21, 2019
Parse JSON scan results file from a SQL Vulnerability Assessment Tool into a relational structure
View Parse Vulnerability Assessment Scan Json File.sql
DECLARE @j NVARCHAR(MAX)
SELECT @j = BulkColumn
FROM OPENROWSET (
BULK 'C:\Temp\vat_example_results_file.json'
, SINGLE_NCLOB) FileName
IF ISJSON(@j) = 1
PRINT N'Imported JSON is valid'
@EitanBlumin
EitanBlumin / PrintMax Minified Temporary Procedure.sql
Last active Jul 16, 2019
This is a minified version of the PrintMax procedure (originally written by Ben Dill). It's created as a temporary procedure.
View PrintMax Minified Temporary Procedure.sql
IF OBJECT_ID('tempdb..#PrintMax') IS NOT NULL DROP PROC #PrintMax;
GO
CREATE PROCEDURE #PrintMax @str NVARCHAR(MAX)
AS
BEGIN
IF (@str IS NULL) RETURN;
DECLARE @LBindex INT,@len INT;
SET @len = 4000;
WHILE (LEN(@str) > @len) BEGIN
SET @LBindex = CHARINDEX((CHAR(10) + CHAR(13)) COLLATE database_default, REVERSE(LEFT(@str, @len)) COLLATE database_default);
View Asynchronous_Triggers_ServiceBroker_Example.sql
USE AdventureWorks2008R2
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF OBJECT_ID('Purchasing.usp_AT_uPurchaseOrderDetail', 'P') IS NOT NULL
DROP PROCEDURE Purchasing.usp_AT_uPurchaseOrderDetail;
GO
CREATE PROCEDURE Purchasing.usp_AT_uPurchaseOrderDetail
View trello_cards_to_github_issues.ps1
param (
[Parameter(Mandatory)][string] $GitHubToken,
[Parameter(Mandatory)][string] $GitHubOwner,
[Parameter(Mandatory)][string] $GitHubRepo,
[Parameter(Mandatory)][string] $SourceTrelloJsonFile,
[string[]] $TrelloLists,
[bool] $UpdateExistingIssuesByTitle = $true,
[bool] $AddNonExistingIssues = $true,
[bool] $Logging = $true
)
@EitanBlumin
EitanBlumin / realign_identity_to_max_value.sql
Last active Feb 26, 2019
Re-align Identity Last Value to Actual Max Value
View realign_identity_to_max_value.sql
DECLARE @CurrTable SYSNAME, @CurrCol SYSNAME, @LastValue BIGINT
DECLARE @CMD NVARCHAR(MAX), @Result NVARCHAR(MAX)
DECLARE Cur CURSOR
LOCAL FAST_FORWARD
FOR
SELECT DISTINCT QUOTENAME(OBJECT_SCHEMA_NAME(t.object_id)) + '.' + QUOTENAME(OBJECT_NAME(t.object_id)), c.name, CONVERT(int, c.last_value)
FROM sys.identity_columns AS c
INNER JOIN sys.tables AS t
ON c.object_id = t.object_id
@EitanBlumin
EitanBlumin / Review SQL Instance Best Practices.sql
Last active Feb 13, 2019
Condensed SQL Server Checkup of most common and impactful best practices
View Review SQL Instance Best Practices.sql
DECLARE
@NumOfMinutesBackToCheck INT = 360,
@MinutesBackToCheck INT = 360,
@DaysBackToCheck INT = 10,
@MinAdHocSizeInMB INT = 200,
@MinAdHocPercent INT = 25,
@FreespaceMinimumMB INT = 1024,
@FreespaceMinimumPercent INT = 10,
@UnsentLogThresholdKB INT = 2048,
@UnrestoredLogThresholdKB INT = 2048,
View Generate_Merge_For_All_Tables.sql
/*
===================================================
Generate MERGE Statements for All Tables
===================================================
Copyright: Eitan Blumin (C) 2012
Email: eitan@madeiradata.com
Source: www.madeiradata.com
Disclaimer:
The author is not responsible for any damage this
@EitanBlumin
EitanBlumin / Generate Procedure Unit Test with Auto-Comparison.sql
Last active Jan 16, 2019
Use this script to generate and run a "unit test" for two stored procedures. This script is good as a "sanity check" of sorts, that makes sure the operational effect of two procedures is the same. The script also prints out the duration of each procedure in milliseconds.
View Generate Procedure Unit Test with Auto-Comparison.sql
/**************************************************************************************************/
/* Generate Procedure Unit Test with Automatic Comparison */
/**************************************************************************************************/
-- Author: Eitan Blumin
-- Date: 2018-11-21
-- Description: Use this script to generate and run a "unit test" for two stored procedures.
-- Each procedure is considered to be affecting one or more database tables.
-- The contents of these tables can be compared before and after each unit test,
-- and the results of each of the two stored procedures can be compared.
You can’t perform that action at this time.