SQL Server SELECT where any column contains 'x'

后端 未结 5 2027
無奈伤痛
無奈伤痛 2020-12-01 05:22

Using SQL Server 2008, say I have a table called testing with 80 columns and I want to find a value called foo.

I can do:

S         


        
5条回答
  •  感动是毒
    2020-12-01 06:01

    I think this is one of the best ways of doing it

    SELECT * FROM sys.columns  a
    inner join 
    (
    SELECT object_id
    FROM sys.tables 
    where 
    type='U'--user table
    and name like 'testing' 
    ) b on a.object_id=b.object_id
    WHERE a.name like '%foo%'
    

提交回复
热议问题