Skip to content

Instantly share code, notes, and snippets.

🕵️‍♂️
Figuring it out

Eitan Blumin EitanBlumin

🕵️‍♂️
Figuring it out
View GitHub Profile
@EitanBlumin
EitanBlumin / fix_all_orphan_users.sql
Last active Mar 30, 2020
Fix all orphaned users in current database, or all databases in the instance (more info: https://eitanblumin.com/2018/10/31/t-sql-script-to-fix-orphaned-db-users-easily/)
View fix_all_orphan_users.sql
/*
Author: Eitan Blumin | https://eitanblumin.com
Date Created: 2018-01-02
Last Update: 2020-03-30
Description:
Fix All Orphaned Users Within Current Database, or all databases in the instance.
Handles 3 possible use-cases:
1. Login with same name as user exists - generate ALTER LOGIN to map the user to the login.
2. No login with same name exists - generate DROP USER to delete the orphan user.
3. Orphan user is [dbo] - change the database owner to SA (or whatever SA was renamed to)
View Fix_ServerName_To_MachineName.sql
/*
Author: Eitan Blumin (t: @EitanBlumin | b: eitanblumin.com)
Date: November, 2018
Description:
Update @@SERVERNAME to Actual Machine Name.
Run as-is. The script is idempotent and requires no parameters.
SQL Service restart may be required in order to apply changes.
More info:
https://eitanblumin.com/2018/11/06/how-to-update-servername-to-actual-machine-name/
@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
/*
Author: Eitan Blumin (t: @EitanBlumin | b: eitanblumin.com)
Date: August, 2015
Description:
Use this script to easily roll forward multiple transaction log backups from a given folder.
More info:
https://eitanblumin.com/2018/10/28/t-sql-script-to-roll-forward-transaction-log-backups
*/
DECLARE
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
/*
Author: Eitan Blumin, (t: @EitanBlumin | b: eitanblumin.com)
Date: February, 2018
Description:
The data returned by the script would be a list of execution plans,
their respective SQL statements, the Sub-Tree cost of the statements, and their usecounts.
Using this script, you will be able to identify execution plans that use parallelism,
which may stop using parallelism if you change “cost threshold for parallelism” to a value
@EitanBlumin
EitanBlumin / Find_SQL_TCP_Port.sql
Last active May 7, 2018
Find SQL Server Instance TCP Port In Use
View Find_SQL_TCP_Port.sql
USE master
GO
-- Using SQL Error Logs:
xp_readerrorlog 0, 1, N'Server is listening on', N'any', NULL, NULL, N'asc'
-- will also return records for DB Mirroring endpoints
-- also, this won't work if error log was cycled
GO
-- Using currently connected connections:
You can’t perform that action at this time.