# 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

Thursday, August 04, 2005 4:30:51 PM (GMT Daylight Time, UTC+01:00)
You may find it interesting to check out some information about casino on net http://casino-on-net.screwy-casino.com/
online casinos http://www.screwy-casino.com/
online casino gambling http://online-casino-gambling.screwy-casino.com/
slot machines http://slot-machines.screwy-casino.com/
roulette http://roulette.screwy-casino.com/
internet casino http://internet-casino.screwy-casino.com/
casino gambling http://casino-gambling.screwy-casino.com/
casino online http://casino-online.screwy-casino.com/
casino games http://casino-games.screwy-casino.com/
online casino http://online-casino.screwy-casino.com/
...
Monday, February 26, 2007 12:39:19 AM (GMT Standard Time, UTC+00:00)
Your query will return a list of all object that use the specified column. This query will narrow it down to tables only:

SELECT so.name
FROM sysobjects so inner join syscolumns sc
on so.id = sc.id
where sc.name = @fieldName
and OBJECTPROPERTY(so.id, N'IsTable') = 1
ORDER BY so.name
Matt
Comments are closed.