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
View fix_orphan_users_all_dbs.sql
SET NOCOUNT ON;
DECLARE @db SYSNAME, @user NVARCHAR(MAX);
IF OBJECT_ID('tempdb..#tmp') IS NOT NULL DROP TABLE #tmp;
CREATE TABLE #tmp (DBName SYSNAME NULL, UserName NVARCHAR(MAX));
exec sp_MsforEachDB '
INSERT INTO #tmp
SELECT ''?'', dp.name AS user_name
FROM [?].sys.database_principals AS dp
LEFT JOIN sys.server_principals AS sp ON dp.SID = sp.SID
WHERE sp.SID IS NULL
View fix_orphan_users_current_alldbs.sql
SET NOCOUNT ON;
DECLARE @db SYSNAME, @user NVARCHAR(MAX);
IF OBJECT_ID('tempdb..#tmp') IS NOT NULL DROP TABLE #tmp;
CREATE TABLE #tmp (DBName SYSNAME NULL, UserName NVARCHAR(MAX));
exec sp_MsforEachDB '
INSERT INTO #tmp
SELECT ''?'', dp.name AS user_name
FROM [?].sys.database_principals AS dp
LEFT JOIN sys.server_principals AS sp ON dp.SID = sp.SID
WHERE sp.SID IS NULL
View Fix_ServerName_To_MachineName.sql
DECLARE @MachineName NVARCHAR(60)
SET @MachineName = CONVERT(nvarchar,SERVERPROPERTY('ServerName'));
IF @MachineName IS NULL
BEGIN
PRINT 'Could not retrieve machine name using SERVERPROPERTY!';
GOTO Quit;
END
DECLARE @CurrSrv VARCHAR(MAX)
@EitanBlumin
EitanBlumin / zendesk_set_primary_and_secondary_sla.ps1
Created Apr 24, 2018
Zendesk API - Set Primary and Secondary Talk Agents and Availability
View zendesk_set_primary_and_secondary_sla.ps1
param
(
[string] $PrimaryNinja = "Jane Doe",
[string] $SecondaryNinja = "John Smith"
)
$global:zendesk_user_name = "myaccount@mydomain.com/token" # The /token part is obligatory when using Zendesk's API
$global:zendesk_password = "put_your_zendesk_API_token_here"
$global:zendesk_address = "https://your_zendesk_subdomain_here.zendesk.com"
$global:primarySLAgroupname = "SLA Primary"
View ParseXMLFilterParameters_Example.sql
/*
Fully Parameterized Search Query
--------------------------------
Copyright Eitan Blumin (c) 2014; email: eitan@madeiradata.com
You may use the contents of this SQL script or parts of it, modified or otherwise
for any purpose that you wish (including commercial).
Under the single condition that you include in the script
this comment block unchanged, and the URL to the original source, which is:
http://www.madeiradata.com/author/eitan/
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 Multi_Threading_ServiceBroker_Example.sql
/*
===================================================
Service Broker Sample 1: Parallel Querying
===================================================
Copyright: Eitan Blumin (C) 2012
Email: eitan@madeira.co.il
Source: www.madeira.co.il
Disclaimer:
The author is not responsible for any damage this
script or any of its variations may cause.
View Roll_Forward_Transaction_Log_Backups.sql
DECLARE
@TransactionLogBackupFolder VARCHAR(4000) = 'C:\SqlDBBackupsMyDB'
, @FileNameQualifier VARCHAR(4000) = 'MyDB_%.trn'
, @DatabaseName SYSNAME = 'MyDB'
, @PerformRecovery BIT = 0
SET NOCOUNT ON;
DECLARE @Output AS TABLE (Msg NVARCHAR(MAX));
DECLARE @CMD VARCHAR(4000)
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
View Plan_To_Increase_Cost_Threshold_For_Parallelism.sql
DECLARE
@MinUseCount INT = 50 -- Set minimum usecount to ignore rarely-used plans
, @CurrentCostThreshold FLOAT = 5 -- Serves as minimum sub-tree cost
, @MaxSubTreeCost FLOAT = 30 -- Set the maximum sub-tree cost, plans with higher cost than this wouldn't normally interest us
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
SELECT @CurrentCostThreshold = CONVERT(FLOAT, value_in_use)
FROM sys.configurations
WHERE [name] = 'cost threshold for parallelism';
You can’t perform that action at this time.