SQLTeam.com | Weblogs | Forums

Find any particular column among multipel tables


#1

Hi,
Suppose I have 4 tables with unique column names. So is it possible to find any particular column among these 4 tables.


#2

If you want to find which Table a given Column name is in then:

SELECT	S.name + '.' + T.name + '.' + C.name
FROM	sys.columns AS C
	JOIN sys.tables AS T
		 ON T.object_id = C.object_id
	JOIN sys.schemas AS S
		 ON S.schema_id = T.schema_id
WHERE	C.name = 'YourColumnName'

If you mean that you want to query the data, based on a column name, then I'd need to understand the requirement better, but you would probably need dynamic SQL


#3

Nitpick change:

SELECT	S.name + '.' + T.name + '.' + C.name

#4

That's not a nitpick - that's both an Bugifx and an Upgrade !!