# Thursday, December 30, 2004
« Tip of the Day: Formatting Dates | Main | The difference between @@IDENTITY, SCOPE... »

Here's a quick and dirty routine I use all the time. This simple procedure will list all tables in your database where a particular field is found. Not earth shattering by any means, but useful and since I find I use it all the time, I thought someone else might find it userful and same them the brief effort to write their own!

IF EXISTS(SELECT name FROM sysobjects WHERE name = 'sp_findField' AND type='P')
BEGIN
 DROP PROCEDURE sp_findField
END
GO

CREATE PROCEDURE dbo.sp_findField (@fieldName varchar(100))
AS
BEGIN
 SET NOCOUNT ON

 SELECT so.name
 FROM sysobjects so, syscolumns sc
 WHERE so.id = sc.id
 AND sc.name = @fieldName
 ORDER BY so.name

END
GO

GRANT EXECUTE ON sp_findField TO public
GO