This is a mirror of official site: http://jasper-net.blogspot.com/

SQL: how to find table by column name

| Wednesday, October 6, 2010
Hi,

What happens if you have about a hundred tables in unknown database, and all you know - it's column name in a table you look for? - The trick is quite simple: run next stored procedure, while replacing "THE_COLUMN_NAME" with your column name.

SELECT name FROM sysobjects WHERE id IN ( SELECT id FROM syscolumns WHERE name = 'THE_COLUMN_NAME' )

This one is good for a case, while you know only a part of column name:

SELECT name FROM sysobjects WHERE id IN ( SELECT id FROM syscolumns WHERE name like '%PART_OF_NAME%' )

Read more: Yonathan Masovich

Posted via email from .NET Info

0 comments: