How can I search all columns in a table?

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

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

6条回答
  •  暖寄归人
    2020-12-15 07:07

    I did this before in a project. The best way to search all columns in SQL would be to create a new column in the table and paste each columns text/data into it like so:

    table:
    |---------------------------------------------------|
    | column1 | column2 | search_column |
    |---------------------------------------------------|
    | fooxxxxx | barxxxx | fooxxxxx barxxxx |
    ----------------------------------------------------|

    SELECT search_column FROM table1 LIKE %key word%

    It works and gets the job done without writing lots of SQL code. It is also much faster to run this type of query. The only drawback is that when the table is updated and created the search_column has to be constructed.

提交回复
热议问题