0

我想在表格中搜索出现的单词。在我的表中有 80 列可用。是否有可能在不重复所有列的类似运算符的情况下搜索单词。我试图在网上解决这个问题,但我找不到解决方案。提前致谢。

4

2 回答 2

4

This almost certainly means you have major design problems in your schema and need to look at further normalization.

If it makes sense to search for a value over 80 columns... well, yeah, re-think your schema.

In theory you can do:

SELECT *
FROM the_table
WHERE the_table::text LIKE '%word%';

which converts the whole tuple to its text form and then searches it. This is in practice a terrible idea, though; it'll include all columns, not just the text columns you want, it'll add quotes and other formatting for the row literal, and it won't tell you which column(s) the word appeared in.

The saner approach would usually be to use in-database full-text search, which supports multi-column searches. Over 80 columns that's going to be awkward because you do have to repeat all the columns, but it's the only sane way to proceed. If it's too much hassle, you probably need to fix your schema design.

于 2013-07-15T07:11:38.503 回答
-2

Try this,

Below query based on Columnwise.

select COUNT(*) from dbo.TableNAme
where PatIndex('searchword',ColumnName) > 0
于 2013-07-15T07:12:16.567 回答