How can I search all columns in a table?

后端 未结 6 1436
天涯浪人
天涯浪人 2020-12-15 06:41

How can I search all columns of a table in SQL Server?

6条回答
  •  再見小時候
    2020-12-15 06:54

    I don't believe there is any shortcut for this, you have to specify out the list of columns you wish to search. I would argue that if you find yourself trying to do this alot, you probably could improve upon the DB design.

    SELECT * 
    FROM MyTable 
    WHERE Col1 LIKE '%foo%' OR 
          Col2 LIKE '%foo%' OR  
          Col3 LIKE '%foo%' OR 
          Col4 LIKE '%foo%' OR 
          Col5 LIKE '%foo%' OR 
          Col6 LIKE '%foo%'
    

提交回复
热议问题