Link to home
Start Free TrialLog in
Avatar of Jeff S
Jeff SFlag for United States of America

asked on

SQL 2005 Coding question

How can I scan all my tables against my db and find the ones that contain a specific fieldname? I want to find all instances were I have a field name "PreviousPatientProfileId"

ASKER CERTIFIED SOLUTION
Avatar of chapmandew
chapmandew
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial

select 
	t.name
from 
	sysobjects t
	inner join sys.columns c on c.object_id = t.id
where
	c.name like ('%PreviousPatientProfileId%')

Open in new window

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Use this
USE <YOUR DATABASE>;
SELECT TABLE_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE
COLUMN_NAME = 'PreviousPatientProfileId';

Open in new window

I would Also suggest:
(This will search all your stored procs to see if you are using the field there as well

declare @Text nvarchar(100)
set @Text = '%PreviousPatientProfileId%'

SELECT OBJECT_NAME(id) 
    FROM syscomments 
    WHERE [text] LIKE @Text
    AND OBJECTPROPERTY(id, 'IsProcedure') = 1 
    GROUP BY OBJECT_NAME(id)

Open in new window

Avatar of Jeff S

ASKER

THANKS!