September 15, 2013 at 5:35 am
Hi All,
I have list of columns (say col1,col2,col3). I need to find the table in the database which contains these 3 columns. Please suggest.
Regards
Jim
September 15, 2013 at 5:45 am
You can query the sys.columns metadata view to see what tables have particular columns in them.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
September 16, 2013 at 6:09 am
select * from information_schema.columns
where column_name like '%col1%'
OR column_name like '%col2%' OR column_name like '%col3%'
-------Bhuvnesh----------
I work only to learn Sql Server...though my company pays me for getting their stuff done;-)
September 16, 2013 at 10:03 am
SELECT
OBJECT_NAME(object_id) AS table_name
FROM sys.columns
WHERE
name IN ( 'col1', 'col2', 'col3' ) AND
OBJECTPROPERTYEX (object_id, 'BaseType') IN ( 'U', 'V' )
GROUP BY
object_id
HAVING
COUNT(*) = 3
SQL DBA,SQL Server MVP(07, 08, 09) "It's a dog-eat-dog world, and I'm wearing Milk-Bone underwear." "Norm", on "Cheers". Also from "Cheers", from "Carla": "You need to know 3 things about Tortelli men: Tortelli men draw women like flies; Tortelli men treat women like flies; Tortelli men's brains are in their flies".
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply