Skip to content

Instantly share code, notes, and snippets.

View EitanBlumin's full-sized avatar
🕵️‍♂️
Figuring it out

Eitan Blumin EitanBlumin

🕵️‍♂️
Figuring it out
View GitHub Profile
@EitanBlumin
EitanBlumin / fix_all_orphan_users.sql
Last active October 31, 2023 07:47
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/)
/*
Author: Eitan Blumin | https://eitanblumin.com | https://madeiradata.com
Date Created: 2018-01-02
Last Update: 2023-06-18
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. Login with a different name but the same sid exists - generate ALTER LOGIN to map the user to the login.
3. Login SID is identifiable but login doesn't exist in SQL - generate CREATE LOGIN FROM WINDOWS to create a Windows authentication login.
/*
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 April 24, 2018 09:25
Zendesk API - Set Primary and Secondary Talk Agents and Availability
param
(
[string] $PrimaryNinja = "Jane Doe",
[string] $SecondaryNinja = "John Smith"
)
$global:zendesk_user_name = "[email protected]/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"
/*
Fully Parameterized Search Query
--------------------------------
Copyright Eitan Blumin (c) 2014; email: [email protected]
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/
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
/*
===================================================
Service Broker Sample 1: Parallel Querying
===================================================
Copyright: Eitan Blumin (C) 2012
Email: [email protected]
Source: www.madeira.co.il
Disclaimer:
The author is not responsible for any damage this
script or any of its variations may cause.
/*
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
/*
===================================================
Generate MERGE Statements for All Tables
===================================================
Copyright: Eitan Blumin (C) 2012
Email: [email protected]
Source: www.madeiradata.com
Disclaimer:
The author is not responsible for any damage this
/*
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 08:21
Find SQL Server Instance TCP Port In Use
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: