April 29, 2005 at 7:39 am
Hi guys,
I've heard there is a sql command which allows you to query a whole db for a certain column name and it will tell you what tables contani that column. Ie if you search for Customer_ID, it will tell you taht Customer_Details, Customer_Address, and so on all contain thiscolumn.
Thanks!
Alex
April 29, 2005 at 7:47 am
Try:
SELECT Table_Name
FROM Information_Schema.Columns
WHERE Column_Name = 'myCol'
Hope this helps
April 29, 2005 at 7:48 am
SELECT dbo.sysobjects.name AS TableName, dbo.syscolumns.*
FROM dbo.sysobjects INNER JOIN
dbo.syscolumns ON dbo.sysobjects.id = dbo.syscolumns.id
WHERE (dbo.sysobjects.xtype = 'u') AND (dbo.syscolumns.name = 'id')
April 29, 2005 at 7:49 am
In case you didn't notice I was KIDDING about the shrine. All I need as a temple
.
April 29, 2005 at 8:02 am
did it again!
my hero!
April 29, 2005 at 8:04 am
BTW if you even plan to use SQL SERVER 2005 you're better off with this solution :
SELECT Table_Name
FROM Information_Schema.Columns
WHERE Column_Name = 'myCol'
Since I hear that direct access to the system tables will be forbidden in Yukon... Also there's always the fact that it can be modified without any notice when a patch or a new version comes out.
May 2, 2005 at 1:29 am
Yes, whenever you can use the INFORMATION_SCHEMA views instead of directly querying the system tables, you should do so. ![]()
And yes, SQL Server 2005 might be more restrictive here. ![]()
Btw Remi, congrats on crossing to 1,000 posts barrier. ![]()
--
Frank Kalis
Microsoft SQL Server MVP
Webmaster: http://www.insidesql.org/blogs
My blog: http://www.insidesql.org/blogs/frankkalis/[/url]
May 2, 2005 at 5:57 am
Tx Frank... Still a long way from catching you.
Viewing 8 posts - 1 through 8 (of 8 total)
You must be logged in to reply to this topic. Login to reply