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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Help required

Author  Topic 

rammohan
Posting Yak Master

212 Posts

Posted - 2008-10-10 : 03:28:18
Dear All,
I have n number of tables in my database x. here i want to list all the tables names which have column name 'y' in their design. how can i write query?

One can never consent to creep,when one feels an impulse to soar
RAMMOHAN

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-10-10 : 03:49:53
SELECT TABLE_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE COLUMN_NAME='y'
Go to Top of Page

rammohan
Posting Yak Master

212 Posts

Posted - 2008-10-10 : 05:30:45
Thanq very much visakh it's helped, but along with tables it is giving views also, how can i restrict it to only tablenames?

One can never consent to creep,when one feels an impulse to soar
RAMMOHAN

Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-10-10 : 06:14:31
[code]SELECT c.TABLE_NAME
FROM INFORMATION_SCHEMA.COLUMNS AS c
INNER JOIN INFORMATION_SCHEMA.TABLES AS t ON t.TABLE_CATALOG = c.TABLE_CATALOG
AND t.TABLE_SCHEMA = c.TABLE_SCHEMA
AND t.TABLE_NAME = c.TABLE_NAME
AND t.TABLE_TYPE = 'BASE TABLE'
WHERE c.COLUMN_NAME = 'y'[/code]


E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

rammohan
Posting Yak Master

212 Posts

Posted - 2008-10-10 : 07:59:55
Thank you very much Peso.its helped me

One can never consent to creep,when one feels an impulse to soar
RAMMOHAN

Go to Top of Page
   

- Advertisement -