This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Tables Relationship Script | |
-- Script By: Syed Muhammad Yasir for http://connectsql.blogspot.com | |
-- Updated August 1, 2012 | |
-- | |
SELECT CASE WHEN a.parent_object_id IS NULL | |
THEN parent.name + '-1--*-' + child.name | |
ELSE parent.name + '-1--1-' + child.name | |
END AS TablesWithRelations |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/************************ | |
Script Purpose: To Keep Database Restore Log | |
Script By : Aasim Abdullah for https://connectsql.blogspot.com | |
************************/ | |
USE master | |
GO | |
CREATE TABLE DatabaseRestoreLog | |
(DatabaseName VARCHAR(50), RestoreDate DATETIME, RestoredFrom VARCHAR(500)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*************************************************** | |
Purpose: To create a trace and saving it to a file | |
Created by: AASIM ABDULLAH | |
For http://connectsql.blogspot.com | |
Date: 08/29/2012 | |
****************************************************/ | |
-- Create a Queue | |
DECLARE @rc INT | |
DECLARE @TraceID INT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DECLARE @TraceID INT | |
SELECT TOP 1 @TraceID = id FROM sys.traces | |
WHERE path LIKE '%_AutoTrace%' | |
exec sp_trace_setstatus @TraceID, 0 --Stop trace | |
exec sp_trace_setstatus @TraceID, 2 --Close trace |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
USE [msdb] | |
GO | |
/* ====================================================== | |
Script By: Aasim Abdullah @http://connectsql.blogspot.com | |
Script For: Create trigger on msdb.dbo.sysjobs table, | |
to detect any change in job status by any | |
user and mail it to DB team | |
-- =================================================== */ | |
CREATE TRIGGER [dbo].[JobStatusAlert] | |
ON [dbo].[sysjobs] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT '[' + Sch.name + '].[' + Tab.[name] + ']' AS TableName, | |
Ind.[name] AS IndexName, | |
SUBSTRING(( SELECT ', ' + AC.name | |
FROM sys.[tables] AS T | |
INNER JOIN sys.[indexes] I ON T.[object_id] = I.[object_id] | |
INNER JOIN sys.[index_columns] IC ON I.[object_id] = IC.[object_id] | |
AND I.[index_id] = IC.[index_id] | |
INNER JOIN sys.[all_columns] AC ON T.[object_id] = AC.[object_id] | |
AND IC.[column_id] = AC.[column_id] | |
WHERE Ind.[object_id] = I.[object_id] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--| Create By: Aasim Abdullah | |
--| Description: Function takes a string and section number of string which | |
--| is required and separator, which separates different | |
--| sections of given string | |
--| How To Use: SELECT dbo.usp_stringpart('First,Second,Third,Forth,Fifth',3,',') | |
CREATE FUNCTION dbo.usp_stringpart | |
( | |
@InputString NVARCHAR(1000), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
USE mssqlsystemresource | |
GO | |
alter procedure sys.sp_dbcmptlevel | |
@dbname sysname = NULL, -- database name to change | |
@new_cmptlevel tinyint = NULL OUTPUT -- the new compatibility level to change to | |
as | |
set nocount on | |
declare @exec_stmt nvarchar(max) | |
declare @returncode int |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Script By: Aasim Abdullah for http://connectsql.blogspot.com | |
Get all indexes list with key columns and include columns as well as usage statistics | |
*/ | |
SELECT '[' + Sch.name + '].[' + Tab.[name] + ']' AS TableName, | |
Ind.type_desc, | |
Ind.[name] AS IndexName, | |
SUBSTRING(( SELECT ', ' + AC.name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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, |
OlderNewer