Skip to content

Instantly share code, notes, and snippets.

@lionofdezert
lionofdezert / SYNC_Indexes.sql
Created November 29, 2013 18:50
Stored Procedure, to create missing indexes on tables values at target database by comparing both source and target databases.
--DROP IF ALREADY EXISTS
IF EXISTS ( SELECT 1
FROM SYS.PROCEDURES
WHERE NAME = 'SYNC_Indexes' )
DROP PROCEDURE SYNC_Indexes
GO
--CREATE PROCEDURE
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
@lionofdezert
lionofdezert / SYNC_CreatePrimaryKeys.sql
Created November 29, 2013 18:48
Stored Procedure, to create missing primary keys at target database by comparing both source and target databases.
--DROP IF ALREADY CREATED
IF EXISTS ( SELECT 1
FROM SYS.procedures
WHERE NAME = 'SYNC_CreatePrimaryKeys' )
DROP PROC SYNC_CreatePrimaryKeys
GO
--CREATE PROCEDURE
SET ANSI_NULLS ON
GO
@lionofdezert
lionofdezert / SYNC_CreateMissingColumns.sql
Created November 29, 2013 18:46
Stored Procedure, to create missing columns at target database by comparing both source and target databases.
--DROP IF ALREADY CREATED
IF EXISTS (SELECT 1 FROM sys.objects WHERE type = 'P' AND name = 'SYNC_CreateMissingColumns')
DROP PROC [dbo].[SYNC_CreateMissingColumns]
GO
--CREATE PROCEDURE
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*
@lionofdezert
lionofdezert / SYNC_ColumnsDefaultValues.sql
Created November 29, 2013 18:40
Stored Procedure, to create missing columns default values at target database by comparing both source and target databases.
--DROP IF ALREADY EXISTS
IF EXISTS ( SELECT 1
FROM SYS.procedures
WHERE NAME = 'SYNC_ColumnsDefaultValues' )
DROP PROC SYNC_ColumnsDefaultValues
GO
--CREATE PROCEDURE
SET ANSI_NULLS ON
GO
@lionofdezert
lionofdezert / SYNC_CreateForignKeys.sql
Created November 29, 2013 18:38
Stored Procedure, to create missing foreign keys at target database after comparing both source and target databases.
--DROP IF ALREADY CREATED
IF EXISTS (SELECT 1 FROM sys.objects WHERE type = 'P' AND name = 'SYNC_CreateForignKeys')
DROP PROC [dbo].[SYNC_CreateForignKeys]
GO
--CREATE PROCEDURE
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
@lionofdezert
lionofdezert / Sync_CreateMissingTables.sql
Last active December 27, 2015 12:29
Script to find and create missing tables to synchronize two databases
--DROP IF ALREADY CREATED
IF EXISTS (SELECT 1 FROM sys.objects WHERE type = 'P' AND name = 'SYNC_CreateMissingTables')
DROP PROC [dbo].[SYNC_CreateMissingTables]
GO
--CREATE PROCEDURE
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
@lionofdezert
lionofdezert / ALLOW_PAGE_LOCKS_FIX.sql
Last active December 14, 2015 05:49
Script to fix ALLOW_PAGE_LOCKS option on all indexes of all databases on a particular instance
/***********************************
Script By: Amna Asif
Purpose : To fix ALLOW_PAGE_LOCKS option on
all indexes of all databases on a particular instance
***********************************/
USE MASTER
GO
SET QUOTED_IDENTIFIER ON
GO
SET ARITHABORT ON
@lionofdezert
lionofdezert / DDLChangeLogServiceBrokerClientIP.sql
Created December 27, 2012 10:42
DDL Changes Log additional changes in script to get client IP
GO
USE [ConnectDBA]
GO
/*Alter table to add new column to hold client machine IP*/
ALTER TABLE [dbo].[DDLChangeLog] ADD [ClientMachineIP] [varchar](20) NULL
GO
--Create a stored procedure which will hold logic, how to get data from queue and insert to DDLChangeLog table.
CREATE PROCEDURE [ConnectDBA_Queue_EventNotificatier]
WITH EXECUTE AS OWNER
@lionofdezert
lionofdezert / DDLChangeLogServiceBroker..sql
Last active July 6, 2017 21:18
To create DDL Change Log using Service Broker, for multiple databases on a single instance
/*
Script By: Aasim Abdullah/Amna Asif for ConnectSQL
Purpose: To create DDL Change Log using Service Broker,
for multiple databases on a single instance
*/
IF NOT EXISTS (SELECT 1 FROM sys.databases WHERE name = 'ConnectDBA')
CREATE DATABASE ConnectDBA
GO
USE [ConnectDBA]
GO
@lionofdezert
lionofdezert / TablesInSPsWithoutIndexes.sql
Created November 29, 2012 14:12
Script to get list of stored procedures which contains tables but without non clusterd indexes
/*
Script By: Aasim Abdullah for http://connectsql.blogspot.com
Purpose: To get list of stored procedures which contains tables but without non clusterd indexes
*/
SELECT *
FROM ( SELECT SCHEMA_NAME(schema_id) + '.' + NAME AS ProcedureName,