Last active
December 16, 2015 22:08
-
-
Save GeorgeDellinger/5504405 to your computer and use it in GitHub Desktop.
MS SQL Synonym helper Find out where the synonym is pointing. Gets added to the master db of your server. Add it to your Tools|Options|Environment|Keyboard Query Shortcuts. Then just highlight a keyword to search and use the shortcut.
This file contains hidden or 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 [master] | |
| GO | |
| SET ANSI_NULLS ON | |
| GO | |
| SET QUOTED_IDENTIFIER ON | |
| GO | |
| if exists (select * from sysobjects where id = object_id(N'[dbo].[sp_FindSynonym]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) | |
| drop procedure [dbo].[sp_FindSynonym] | |
| GO | |
| CREATE Procedure [dbo].[sp_FindSynonym] | |
| @Column varchar(max) | |
| AS | |
| SELECT | |
| name, | |
| base_object_name as synonymDefinition, | |
| COALESCE(PARSENAME(base_object_name,4),@@servername) AS serverName, | |
| COALESCE(PARSENAME(base_object_name,3),DB_NAME(DB_ID())) AS dbName, | |
| COALESCE(PARSENAME(base_object_name,2),SCHEMA_NAME(SCHEMA_ID())) AS schemaName, | |
| PARSENAME(base_object_name,1) AS objectName | |
| FROM sys.synonyms | |
| Where Name LIKE '%'+@Column+'%' | |
| ORDER BY serverName,dbName,schemaName,objectName | |
| GO | |
| EXEC sys.sp_MS_marksystemobject sp_FindSynonym | |
| GO |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment