Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 finding tables having a particular column

Author  Topic 

mathiyazhagan.sekar@gmail
Starting Member

11 Posts

Posted - 2008-05-19 : 05:24:23
Hi All,
How to find all the tables of a database containing a column . for example,how list all the tables of employee database having employeeid ?

Cheers,
Mathi
India.

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-05-19 : 05:25:44
select table_name from information_schema.columns where column_name = 'employeeid'



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

ranganath
Posting Yak Master

209 Posts

Posted - 2008-05-19 : 05:27:17
Hi,

Try with this

Select distinct Object_name(id) From sys.syscolumns where name = 'EmployeeId'
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-05-19 : 05:57:43
quote:
Originally posted by ranganath

Hi,

Try with this

Select distinct Object_name(id) From sys.syscolumns where name = 'EmployeeId'


or

Select distinct object_name(object_id) From sys.columns where name = 'EmployeeId'

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

Lumbago
Norsk Yak Master

3271 Posts

Posted - 2008-05-19 : 06:23:47
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=65666

--
Lumbago
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-05-19 : 06:41:38
sp_msforeachtable 'IF COL_LENGTH(''?'',''YourColumnName'') >0 SELECT ''?'''
Go to Top of Page

saruva
Starting Member

1 Post

Posted - 2008-06-02 : 21:56:52
select o.name as table_name, s.name as column_name
from dbo.syscolumns s, dbo.sysobjects o
where s.name like '%employee_id%'
and s.id = o.id

sundar saruva
Go to Top of Page
   

- Advertisement -