{"id":181720,"date":"2020-05-21T08:14:43","date_gmt":"2020-05-21T00:14:43","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=181720"},"modified":"2020-05-11T09:15:27","modified_gmt":"2020-05-11T01:15:27","slug":"sqlserver-table-partition","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/sqlserver-table-partition.html","title":{"rendered":"SQL Server\u8868\u5206\u533a\u64cd\u4f5c\u8be6\u89e3"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\nSQL Server 2005\u5f15\u5165\u7684\u8868\u5206\u533a\u6280\u672f\uff0c\u8ba9\u7528\u6237\u80fd\u591f\u628a\u6570\u636e\u5206\u6563\u5b58\u653e\u5230\u4e0d\u540c\u7684\u7269\u7406\u78c1\u76d8\u4e2d\uff0c\u63d0\u9ad8\u8fd9\u4e9b\u78c1\u76d8\u7684\u5e76\u884c\u5904\u7406\u6027\u80fd\u4ee5\u4f18\u5316\u67e5\u8be2\u6027\u80fd\u2026\u2026
\n<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

SQL Server\u6570\u636e\u5e93\u8868\u5206\u533a\u64cd\u4f5c\u8fc7\u7a0b\u7531\u4e09\u4e2a\u6b65\u9aa4\u7ec4\u6210\uff1a<\/p>\n

1. \u521b\u5efa\u5206\u533a\u51fd\u6570<\/p>\n

2. \u521b\u5efa\u5206\u533a\u67b6\u6784<\/p>\n

3. \u5bf9\u8868\u8fdb\u884c\u5206\u533a
\n\u4e0b\u9762\u5c06\u5bf9\u6bcf\u4e2a\u6b65\u9aa4\u8fdb\u884c\u8be6\u7ec6\u4ecb\u7ecd\u3002<\/p>\n

\u6b65\u9aa4\u4e00\uff1a\u521b\u5efa\u4e00\u4e2a\u5206\u533a\u51fd\u6570<\/strong><\/div>\n

\u6b64\u5206\u533a\u51fd\u6570\u7528\u4e8e\u5b9a\u4e49\u4f60\u5e0c\u671bSQL Server\u5982\u4f55\u5bf9\u6570\u636e\u8fdb\u884c\u5206\u533a\u7684\u53c2\u6570\u503c([u]how[\/u])\u3002\u8fd9\u4e2a\u64cd\u4f5c\u5e76\u4e0d\u6d89\u53ca\u4efb\u4f55\u8868\u683c\uff0c\u53ea\u662f\u5355\u7eaf\u7684\u5b9a\u4e49\u4e86\u4e00\u9879\u6280\u672f\u6765\u5206\u5272\u6570\u636e\u3002<\/p>\n

\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u6307\u5b9a\u6bcf\u4e2a\u5206\u533a\u7684\u8fb9\u754c\u6761\u4ef6\u6765\u5b9a\u4e49\u5206\u533a\u3002\u4f8b\u5982\uff0c\u5047\u5b9a\u6211\u4eec\u6709\u4e00\u4efdCustomers\u8868\uff0c\u5176\u4e2d\u5305\u542b\u4e86\u5173\u4e8e\u6240\u6709\u5ba2\u6237\u7684\u4fe1\u606f\uff0c\u4ee5\u4e00\u4e00\u5bf9\u5e94\u7684\u5ba2\u6237\u7f16\u53f7(\u4ece1\u52301,000,000)\u6765\u533a\u5206\u3002\u6211\u4eec\u5c06\u901a\u8fc7\u4ee5\u4e0b\u7684\u5206\u533a\u51fd\u6570\u628a\u8fd9\u4e2a\u8868\u5206\u4e3a\u56db\u4e2a\u5927\u5c0f\u76f8\u540c\u7684\u5206\u533a\uff1a<\/p>\n

CREATE PARTITION FUNCTION customer_partfunc (int)\r\n\u3000\u3000AS RANGE RIGHT\r\n\u3000\u3000FOR VALUES (250000, 500000, 750000)\r\n<\/pre>\n

\u8fd9\u4e9b\u8fb9\u754c\u503c\u5b9a\u4e49\u4e86\u56db\u4e2a\u5206\u533a\u3002\u7b2c\u4e00\u4e2a\u5206\u533a\u5305\u62ec\u6240\u6709\u503c\u5c0f\u4e8e250,000\u7684\u6570\u636e\uff0c\u7b2c\u4e8c\u4e2a\u5206\u533a\u5305\u62ec\u503c\u5728250,000\u523049,999\u4e4b\u95f4\u7684\u6570\u636e\u3002\u7b2c\u4e09\u4e2a\u5206\u533a\u5305\u62ec\u503c\u5728500,000\u52307499,999\u4e4b\u95f4\u7684\u6570\u636e\u3002\u6240\u6709\u503c\u5927\u4e8e\u6216\u7b49\u4e8e750,000\u7684\u6570\u636e\u88ab\u5f52\u5165\u7b2c\u56db\u4e2a\u5206\u533a\u3002<\/p>\n

\u8bf7\u6ce8\u610f\uff0c\u8fd9\u91cc\u8c03\u7528\u7684\"RANGE RIGHT\"\u8bed\u53e5\u8868\u660e\u6bcf\u4e2a\u5206\u533a\u8fb9\u754c\u503c\u662f\u53f3\u754c\u3002\u7c7b\u4f3c\u7684\uff0c\u5982\u679c\u4f7f\u7528\"RANGE LEFT\"\u8bed\u53e5\uff0c\u5219\u4e0a\u8ff0\u7b2c\u4e00\u4e2a\u5206\u533a\u5e94\u8be5\u5305\u62ec\u6240\u6709\u503c\u5c0f\u4e8e\u6216\u7b49\u4e8e250,000\u7684\u6570\u636e\uff0c\u7b2c\u4e8c\u4e2a\u5206\u533a\u7684\u6570\u636e\u503c\u5728250,001\u5230500,000\u4e4b\u95f4\uff0c\u4ee5\u6b64\u7c7b\u63a8\u3002<\/p>\n

\u6b65\u9aa4\u4e8c\uff1a\u521b\u5efa\u4e00\u4e2a\u5206\u533a\u67b6\u6784<\/strong><\/div>\n

\u4e00\u65e6\u7ed9\u51fa\u63cf\u8ff0\u5982\u4f55\u5206\u5272\u6570\u636e\u7684\u5206\u533a\u51fd\u6570\uff0c\u63a5\u7740\u5c31\u8981\u521b\u5efa\u4e00\u4e2a\u5206\u533a\u67b6\u6784\uff0c\u7528\u6765\u5b9a\u4e49\u5206\u533a\u4f4d\u7f6e([u]where[\/u])\u3002\u521b\u5efa\u8fc7\u7a0b\u975e\u5e38\u76f4\u622a\u4e86\u5f53\uff0c\u53ea\u8981\u5c06\u5206\u533a\u8fde\u63a5\u5230\u6307\u5b9a\u7684\u6587\u4ef6\u7ec4\u5c31\u884c\u4e86\u3002\u4f8b\u5982\uff0c\u5982\u679c\u6709\u56db\u4e2a\u6587\u4ef6\u7ec4\uff0c\u7ec4\u540d\u4ece\"fg1\"\u5230\"fg4\"\uff0c\u90a3\u4e48\u4ee5\u4e0b\u7684\u5206\u533a\u67b6\u6784\u5c31\u80fd\u8fbe\u5230\u60f3\u8981\u7684\u6548\u679c\uff1a<\/p>\n

CREATE PARTITION SCHEME customer_partscheme\r\n\u3000\u3000AS PARTITION customer_partfunc\r\n\u3000\u3000TO (fg1, fg2, fg3, fg4)\r\n<\/pre>\n

\u6ce8\u610f\uff0c\u8fd9\u91cc\u5c06\u4e00\u4e2a\u5206\u533a\u51fd\u6570\u8fde\u63a5\u5230\u4e86\u8be5\u5206\u533a\u67b6\u6784\uff0c\u4f46\u5e76\u6ca1\u6709\u5c06\u5206\u533a\u67b6\u6784\u8fde\u63a5\u5230\u4efb\u4f55\u6570\u636e\u8868\u3002\u8fd9\u5c31\u662f\u53ef\u590d\u7528\u6027\u8d77\u4f5c\u7528\u7684\u5730\u65b9\u4e86\u3002\u65e0\u8bba\u6709\u591a\u5c11\u6570\u636e\u5e93\u8868\uff0c\u6211\u4eec\u90fd\u53ef\u4ee5\u4f7f\u7528\u8be5\u5206\u533a\u67b6\u6784(\u6216\u4ec5\u4ec5\u662f\u5206\u533a\u51fd\u6570)\u3002<\/p>\n

\u6b65\u9aa4\u4e09\uff1a\u5bf9\u4e00\u4e2a\u8868\u8fdb\u884c\u5206\u533a<\/strong><\/div>\n

\u5b9a\u4e49\u597d\u4e00\u4e2a\u5206\u533a\u67b6\u6784\u540e\uff0c\u5c31\u53ef\u4ee5\u7740\u624b\u521b\u5efa\u4e00\u4e2a\u5206\u533a\u8868\u4e86\u3002\u8fd9\u662f\u6574\u4e2a\u5206\u533a\u64cd\u4f5c\u8fc7\u7a0b\u4e2d\u6700\u7b80\u5355\u7684\u4e00\u4e2a\u6b65\u9aa4\u3002\u53ea\u9700\u8981\u5728\u8868\u521b\u5efa\u6307\u4ee4\u4e2d\u6dfb\u52a0\u4e00\u4e2a\"ON\"\u8bed\u53e5\uff0c\u7528\u6765\u6307\u5b9a\u5206\u533a\u67b6\u6784\u4ee5\u53ca\u5e94\u7528\u8be5\u67b6\u6784\u7684\u8868\u5217\u3002\u56e0\u4e3a\u5206\u533a\u67b6\u6784\u5df2\u7ecf\u8bc6\u522b\u4e86\u5206\u533a\u51fd\u6570\uff0c\u6240\u4ee5\u4e0d\u9700\u8981\u518d\u6307\u5b9a\u5206\u533a\u51fd\u6570\u4e86\u3002
\n\u4f8b\u5982\uff0c\u4f7f\u7528\u4ee5\u4e0a\u7684\u5206\u533a\u67b6\u6784\u521b\u5efa\u4e00\u4e2a\u5ba2\u6237\u8868\uff0c\u53ef\u4ee5\u8c03\u7528\u4ee5\u4e0b\u7684Transact-SQL\u6307\u4ee4\uff1a<\/p>\n

CREATE TABLE customers (FirstName nvarchar(40), LastName nvarchar(40), CustomerNumber int)\r\n\u3000\u3000ON customer_partscheme (CustomerNumber)\r\n<\/pre>\n

\u5173\u4e8eSQL Server\u7684\u8868\u5206\u533a\u529f\u80fd\uff0c\u4f60\u77e5\u9053\u4e0a\u8ff0\u7684\u76f8\u5173\u77e5\u8bc6\u5c31\u8db3\u591f\u4e86\u3002\u8bb0\u4f4f!\u7f16\u5199\u80fd\u591f\u7528\u4e8e\u591a\u4e2a\u8868\u7684\u4e00\u822c\u7684\u5206\u533a\u51fd\u6570\u548c\u5206\u533a\u67b6\u6784\u5c31\u80fd\u591f\u5927\u5927\u63d0\u9ad8\u53ef\u590d\u7528\u6027\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

SQL Server\u6570\u636e\u5e93\u8868\u5206\u533a\u64cd\u4f5c\u8fc7\u7a0b\u7531\u4e09\u4e2a\u6b65\u9aa4\u7ec4\u6210\uff1a 1. \u521b\u5efa\u5206\u533a\u51fd\u6570 2. \u521b\u5efa\u5206\u533a\u67b6\u6784 3. \u5bf9\u8868\u8fdb […]<\/p>\n","protected":false},"author":1903,"featured_media":76387,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-181720","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/181720","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/1903"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=181720"}],"version-history":[{"count":7,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/181720\/revisions"}],"predecessor-version":[{"id":181758,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/181720\/revisions\/181758"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/76387"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=181720"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=181720"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=181720"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}