{"id":138993,"date":"2024-10-31T17:19:38","date_gmt":"2024-10-31T09:19:38","guid":{"rendered":"https:\/\/server.hk\/cnblog\/138993\/"},"modified":"2024-10-31T17:19:39","modified_gmt":"2024-10-31T09:19:39","slug":"sql-server%e5%85%a8%e6%96%87%e7%b4%a2%e5%bc%95%e7%9a%84%e7%94%a8%e6%b3%95","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/138993\/","title":{"rendered":"SQL Server\u5168\u6587\u7d22\u5f15\u7684\u7528\u6cd5"},"content":{"rendered":"<h1 id=\"sql-server%e5%85%a8%e6%96%87%e7%b4%a2%e5%bc%95%e7%9a%84%e7%94%a8%e6%b3%95-exDThqpLfo\">SQL Server\u5168\u6587\u7d22\u5f15\u7684\u7528\u6cd5<\/h1>\n<p>\u5728\u73fe\u4ee3\u6578\u64da\u5eab\u7ba1\u7406\u4e2d\uff0cSQL Server\u7684\u5168\u6587\u7d22\u5f15\u662f\u4e00\u500b\u5f37\u5927\u7684\u5de5\u5177\uff0c\u80fd\u5920\u63d0\u9ad8\u67e5\u8a62\u6027\u80fd\uff0c\u7279\u5225\u662f\u5728\u8655\u7406\u5927\u91cf\u6587\u672c\u6578\u64da\u6642\u3002\u672c\u6587\u5c07\u6df1\u5165\u63a2\u8a0eSQL Server\u5168\u6587\u7d22\u5f15\u7684\u57fa\u672c\u6982\u5ff5\u3001\u4f7f\u7528\u65b9\u6cd5\u53ca\u5176\u512a\u52e2\u3002<\/p>\n<h2 id=\"%e4%bb%80%e9%ba%bc%e6%98%af%e5%85%a8%e6%96%87%e7%b4%a2%e5%bc%95%ef%bc%9f-exDThqpLfo\">\u4ec0\u9ebc\u662f\u5168\u6587\u7d22\u5f15\uff1f<\/h2>\n<p>\u5168\u6587\u7d22\u5f15\u662f\u4e00\u7a2e\u7279\u6b8a\u7684\u7d22\u5f15\u985e\u578b\uff0c\u65e8\u5728\u652f\u6301\u5c0d\u6587\u672c\u6578\u64da\u7684\u9ad8\u6548\u67e5\u8a62\u3002\u8207\u50b3\u7d71\u7684\u7d22\u5f15\u4e0d\u540c\uff0c\u5168\u6587\u7d22\u5f15\u5141\u8a31\u7528\u6236\u5728\u6587\u672c\u5b57\u6bb5\u4e2d\u9032\u884c\u8907\u96dc\u7684\u67e5\u8a62\uff0c\u4f8b\u5982\u67e5\u627e\u5305\u542b\u7279\u5b9a\u55ae\u8a5e\u6216\u77ed\u8a9e\u7684\u8a18\u9304\u3002\u9019\u5c0d\u65bc\u9700\u8981\u8655\u7406\u5927\u91cf\u975e\u7d50\u69cb\u5316\u6578\u64da\u7684\u61c9\u7528\u7a0b\u5e8f\u5c24\u70ba\u91cd\u8981\u3002<\/p>\n<h2 id=\"%e5%a6%82%e4%bd%95%e5%89%b5%e5%bb%ba%e5%85%a8%e6%96%87%e7%b4%a2%e5%bc%95-exDThqpLfo\">\u5982\u4f55\u5275\u5efa\u5168\u6587\u7d22\u5f15<\/h2>\n<p>\u5728SQL Server\u4e2d\uff0c\u5275\u5efa\u5168\u6587\u7d22\u5f15\u7684\u904e\u7a0b\u5305\u62ec\u5e7e\u500b\u6b65\u9a5f\u3002\u9996\u5148\uff0c\u60a8\u9700\u8981\u78ba\u4fdd\u6578\u64da\u5eab\u4e2d\u5df2\u7d93\u5b58\u5728\u4e00\u500b\u5168\u6587\u76ee\u9304\u3002\u63a5\u4e0b\u4f86\uff0c\u60a8\u53ef\u4ee5\u5728\u9700\u8981\u7684\u8868\u4e0a\u5275\u5efa\u5168\u6587\u7d22\u5f15\u3002\u4ee5\u4e0b\u662f\u5275\u5efa\u5168\u6587\u7d22\u5f15\u7684\u57fa\u672c\u6b65\u9a5f\uff1a<\/p>\n<h3 id=\"%e6%ad%a5%e9%a9%9f1%ef%bc%9a%e5%89%b5%e5%bb%ba%e5%85%a8%e6%96%87%e7%9b%ae%e9%8c%84-exDThqpLfo\">\u6b65\u9a5f1\uff1a\u5275\u5efa\u5168\u6587\u76ee\u9304<\/h3>\n<pre><code>CREATE FULLTEXT CATALOG MyFullTextCatalog AS DEFAULT;<\/code><\/pre>\n<p>\u9019\u689d\u547d\u4ee4\u5c07\u5275\u5efa\u4e00\u500b\u540d\u70ba&#8221;MyFullTextCatalog&#8221;\u7684\u5168\u6587\u76ee\u9304\uff0c\u4e26\u5c07\u5176\u8a2d\u7f6e\u70ba\u9ed8\u8a8d\u76ee\u9304\u3002<\/p>\n<h3 id=\"%e6%ad%a5%e9%a9%9f2%ef%bc%9a%e5%89%b5%e5%bb%ba%e5%85%a8%e6%96%87%e7%b4%a2%e5%bc%95-exDThqpLfo\">\u6b65\u9a5f2\uff1a\u5275\u5efa\u5168\u6587\u7d22\u5f15<\/h3>\n<pre><code>CREATE FULLTEXT INDEX ON MyTable(MyTextColumn) \n   KEY INDEX MyPrimaryKeyIndex \n   ON MyFullTextCatalog;<\/code><\/pre>\n<p>\u5728\u9019\u88e1\uff0c&#8221;MyTable&#8221;\u662f\u60a8\u8981\u5275\u5efa\u5168\u6587\u7d22\u5f15\u7684\u8868\u540d\uff0c&#8221;MyTextColumn&#8221;\u662f\u5305\u542b\u6587\u672c\u6578\u64da\u7684\u5217\uff0c&#8221;MyPrimaryKeyIndex&#8221;\u662f\u8a72\u8868\u7684\u4e3b\u9375\u7d22\u5f15\u3002<\/p>\n<h2 id=\"%e4%bd%bf%e7%94%a8%e5%85%a8%e6%96%87%e7%b4%a2%e5%bc%95%e9%80%b2%e8%a1%8c%e6%9f%a5%e8%a9%a2-exDThqpLfo\">\u4f7f\u7528\u5168\u6587\u7d22\u5f15\u9032\u884c\u67e5\u8a62<\/h2>\n<p>\u4e00\u65e6\u5275\u5efa\u4e86\u5168\u6587\u7d22\u5f15\uff0c\u60a8\u5c31\u53ef\u4ee5\u4f7f\u7528`CONTAINS`\u548c`FREETEXT`\u51fd\u6578\u4f86\u67e5\u8a62\u6587\u672c\u6578\u64da\u3002<\/p>\n<h3 id=\"%e4%bd%bf%e7%94%a8contains%e5%87%bd%e6%95%b8-exDThqpLfo\">\u4f7f\u7528CONTAINS\u51fd\u6578<\/h3>\n<pre><code>SELECT * FROM MyTable \nWHERE CONTAINS(MyTextColumn, 'search term');<\/code><\/pre>\n<p>\u9019\u689d\u67e5\u8a62\u5c07\u8fd4\u56de\u6240\u6709\u5305\u542b&#8221;search term&#8221;\u7684\u8a18\u9304\u3002<\/p>\n<h3 id=\"%e4%bd%bf%e7%94%a8freetext%e5%87%bd%e6%95%b8-exDThqpLfo\">\u4f7f\u7528FREETEXT\u51fd\u6578<\/h3>\n<pre><code>SELECT * FROM MyTable \nWHERE FREETEXT(MyTextColumn, 'search term');<\/code><\/pre>\n<p>\u8207`CONTAINS`\u4e0d\u540c\uff0c`FREETEXT`\u6703\u6839\u64da\u8a9e\u7fa9\u9032\u884c\u67e5\u8a62\uff0c\u8fd4\u56de\u8207&#8221;search term&#8221;\u76f8\u95dc\u7684\u6240\u6709\u8a18\u9304\u3002<\/p>\n<h2 id=\"%e5%85%a8%e6%96%87%e7%b4%a2%e5%bc%95%e7%9a%84%e5%84%aa%e5%8b%a2-exDThqpLfo\">\u5168\u6587\u7d22\u5f15\u7684\u512a\u52e2<\/h2>\n<ul>\n<li><strong>\u63d0\u9ad8\u67e5\u8a62\u6027\u80fd\uff1a<\/strong>\u5168\u6587\u7d22\u5f15\u80fd\u5920\u986f\u8457\u63d0\u9ad8\u5c0d\u5927\u91cf\u6587\u672c\u6578\u64da\u7684\u67e5\u8a62\u901f\u5ea6\u3002<\/li>\n<li><strong>\u652f\u6301\u8907\u96dc\u67e5\u8a62\uff1a<\/strong>\u7528\u6236\u53ef\u4ee5\u4f7f\u7528\u591a\u7a2e\u67e5\u8a62\u689d\u4ef6\uff0c\u5982\u77ed\u8a9e\u67e5\u8a62\u3001\u5e03\u723e\u67e5\u8a62\u7b49\u3002<\/li>\n<li><strong>\u9748\u6d3b\u6027\uff1a<\/strong>\u652f\u6301\u591a\u7a2e\u8a9e\u8a00\u548c\u5b57\u7b26\u96c6\uff0c\u9069\u5408\u5168\u7403\u5316\u61c9\u7528\u3002<\/li>\n<\/ul>\n<h2 id=\"%e6%b3%a8%e6%84%8f%e4%ba%8b%e9%a0%85-exDThqpLfo\">\u6ce8\u610f\u4e8b\u9805<\/h2>\n<p>\u5728\u4f7f\u7528\u5168\u6587\u7d22\u5f15\u6642\uff0c\u60a8\u9700\u8981\u6ce8\u610f\u4ee5\u4e0b\u5e7e\u9ede\uff1a<\/p>\n<ul>\n<li>\u5168\u6587\u7d22\u5f15\u4e0d\u652f\u6301\u6240\u6709\u6578\u64da\u985e\u578b\uff0c\u50c5\u652f\u6301\u7279\u5b9a\u7684\u5b57\u7b26\u578b\u6578\u64da\u3002<\/li>\n<li>\u7dad\u8b77\u5168\u6587\u7d22\u5f15\u9700\u8981\u984d\u5916\u7684\u8cc7\u6e90\uff0c\u7279\u5225\u662f\u5728\u6578\u64da\u983b\u7e41\u8b8a\u66f4\u7684\u60c5\u6cc1\u4e0b\u3002<\/li>\n<li>\u5728\u8a2d\u8a08\u6578\u64da\u5eab\u6642\uff0c\u61c9\u6839\u64da\u5be6\u969b\u9700\u6c42\u5408\u7406\u898f\u5283\u5168\u6587\u7d22\u5f15\u7684\u4f7f\u7528\u3002<\/li>\n<\/ul>\n<h2 id=\"%e7%b8%bd%e7%b5%90-exDThqpLfo\">\u7e3d\u7d50<\/h2>\n<p>SQL Server\u7684\u5168\u6587\u7d22\u5f15\u662f\u4e00\u500b\u5f37\u5927\u7684\u5de5\u5177\uff0c\u80fd\u5920\u986f\u8457\u63d0\u9ad8\u6587\u672c\u6578\u64da\u7684\u67e5\u8a62\u6027\u80fd\u3002\u901a\u904e\u5408\u7406\u5730\u5275\u5efa\u548c\u4f7f\u7528\u5168\u6587\u7d22\u5f15\uff0c\u958b\u767c\u8005\u53ef\u4ee5\u66f4\u9ad8\u6548\u5730\u8655\u7406\u548c\u6aa2\u7d22\u5927\u91cf\u975e\u7d50\u69cb\u5316\u6578\u64da\u3002\u5c0d\u65bc\u9700\u8981\u9ad8\u6548\u6578\u64da\u8655\u7406\u7684\u61c9\u7528\uff0c\u9078\u64c7\u5408\u9069\u7684 <a href=\"https:\/\/server.hk\">VPS<\/a> \u89e3\u6c7a\u65b9\u6848\uff0c\u5982 <a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a> \u6216 <a href=\"https:\/\/server.hk\">\u4e91\u670d\u52a1\u5668<\/a>\uff0c\u5c07\u6709\u52a9\u65bc\u63d0\u5347\u6574\u9ad4\u6027\u80fd\u548c\u7528\u6236\u9ad4\u9a57\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e86\u89e3SQL Server\u5168\u6587\u7d22\u5f15\u7684\u7528\u6cd5\uff0c\u63d0\u5347\u6587\u672c\u641c\u7d22\u6548\u7387\uff0c\u5feb\u901f\u67e5\u627e\u548c\u7ba1\u7406\u5927\u91cf\u6570\u636e\u4e2d\u7684\u5173\u952e\u4fe1\u606f\u3002<\/p>\n","protected":false},"author":0,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-138993","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/138993","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=138993"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/138993\/revisions"}],"predecessor-version":[{"id":138994,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/138993\/revisions\/138994"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=138993"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=138993"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=138993"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}