I\'m trying to find all references to an object in an SQL Server database.
How can I quickly search? SQL Server Management Studio does not seem to do it. I use http:
If you want to use OMG Ponies sql as a keyboard shortcut in SSMS, add the following SP to your master db.
USE [master]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[SP_FindAllReferences]
@targetText nvarchar(128)
AS
BEGIN
SET NOCOUNT ON;
declare @origdb nvarchar(128)
select @origdb = db_name()
declare @sql nvarchar(1000)
set @sql = 'USE [' + @origdb +'];'
set @sql += 'select object_name(m.object_id), m.* '
set @sql += 'from sys.sql_modules m where m.definition like N' + CHAR(39) + '%' + @targetText + '%' + CHAR(39)
exec (@sql)
SET NOCOUNT OFF;
END
Then you just need to add dbo.SP_FindAllReferences to your keyboard shortcuts and then you can use it in the context of any DB on your server.
Cheers!
NB: If you are using SQL Server 2005 you will have to replace
@sql +=
with
@sql = @sql +