{"id":59611,"date":"2024-10-12T23:24:16","date_gmt":"2024-10-12T15:24:16","guid":{"rendered":"https:\/\/server.hk\/cnblog\/59611\/"},"modified":"2024-10-12T23:24:16","modified_gmt":"2024-10-12T15:24:16","slug":"comb%e6%95%b8%e6%93%9a%e9%a1%9e%e5%9e%8b%e9%81%b8%e5%8f%96sql-server%e4%b8%bb%e9%8d%b5","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/59611\/","title":{"rendered":"COMB\u6578\u64da\u985e\u578b\u9078\u53d6sql server\u4e3b\u9375"},"content":{"rendered":"<h1 id=\"comb%e6%95%b8%e6%93%9a%e9%a1%9e%e5%9e%8b%e9%81%b8%e5%8f%96sql-server%e4%b8%bb%e9%8d%b5-IiZLpUyUqf\">COMB\u6578\u64da\u985e\u578b\u9078\u53d6SQL Server\u4e3b\u9375<\/h1>\n<p>\u5728\u8a2d\u8a08\u6578\u64da\u5eab\u6642\uff0c\u9078\u64c7\u5408\u9069\u7684\u4e3b\u9375\u662f\u81f3\u95dc\u91cd\u8981\u7684\u3002\u4e3b\u9375\u4e0d\u50c5\u7528\u65bc\u552f\u4e00\u6a19\u8b58\u6578\u64da\u8868\u4e2d\u7684\u6bcf\u4e00\u884c\uff0c\u9084\u5c0d\u6578\u64da\u7684\u5b8c\u6574\u6027\u548c\u6027\u80fd\u6709\u8457\u6df1\u9060\u7684\u5f71\u97ff\u3002\u5728SQL Server\u4e2d\uff0cCOMB\u6578\u64da\u985e\u578b\uff08Combination of GUID and Integer\uff09\u4f5c\u70ba\u4e3b\u9375\u7684\u9078\u64c7\uff0c\u9010\u6f38\u53d7\u5230\u958b\u767c\u8005\u7684\u9752\u775e\u3002\u672c\u6587\u5c07\u63a2\u8a0eCOMB\u6578\u64da\u985e\u578b\u7684\u7279\u9ede\u3001\u512a\u7f3a\u9ede\u4ee5\u53ca\u5982\u4f55\u5728SQL Server\u4e2d\u5be6\u73fe\u3002<\/p>\n<h2 id=\"%e4%bb%80%e9%ba%bc%e6%98%afcomb%e6%95%b8%e6%93%9a%e9%a1%9e%e5%9e%8b%ef%bc%9f-IiZLpUyUqf\">\u4ec0\u9ebc\u662fCOMB\u6578\u64da\u985e\u578b\uff1f<\/h2>\n<p>COMB\u6578\u64da\u985e\u578b\u662f\u4e00\u7a2e\u7d50\u5408\u4e86\u5168\u5c40\u552f\u4e00\u6a19\u8b58\u7b26\uff08GUID\uff09\u548c\u6574\u6578\u7684\u6578\u64da\u985e\u578b\u3002\u5b83\u7684\u4e3b\u8981\u76ee\u7684\u662f\u5728\u4fdd\u8b49\u552f\u4e00\u6027\u7684\u540c\u6642\uff0c\u6e1b\u5c11\u7d22\u5f15\u7684\u5927\u5c0f\u548c\u63d0\u9ad8\u67e5\u8a62\u6027\u80fd\u3002COMB\u7684\u7d50\u69cb\u901a\u5e38\u662f\u5c07\u7576\u524d\u7684\u6642\u9593\u6233\u8207\u4e00\u500b\u96a8\u6a5f\u751f\u6210\u7684GUID\u7d50\u5408\uff0c\u9019\u6a23\u53ef\u4ee5\u5728\u591a\u500b\u6578\u64da\u5eab\u4e4b\u9593\u4fdd\u6301\u552f\u4e00\u6027\u3002<\/p>\n<h2 id=\"comb%e6%95%b8%e6%93%9a%e9%a1%9e%e5%9e%8b%e7%9a%84%e5%84%aa%e9%bb%9e-IiZLpUyUqf\">COMB\u6578\u64da\u985e\u578b\u7684\u512a\u9ede<\/h2>\n<ul>\n<li><strong>\u552f\u4e00\u6027\uff1a<\/strong>COMB\u6578\u64da\u985e\u578b\u80fd\u5920\u4fdd\u8b49\u5728\u5168\u7403\u7bc4\u570d\u5167\u7684\u552f\u4e00\u6027\uff0c\u9019\u5c0d\u65bc\u5206\u4f48\u5f0f\u7cfb\u7d71\u5c24\u70ba\u91cd\u8981\u3002<\/li>\n<li><strong>\u6027\u80fd\u512a\u5316\uff1a<\/strong>\u7531\u65bcCOMB\u7684\u7d50\u69cb\uff0c\u7d22\u5f15\u7684\u5927\u5c0f\u76f8\u5c0d\u8f03\u5c0f\uff0c\u9019\u6709\u52a9\u65bc\u63d0\u9ad8\u67e5\u8a62\u6027\u80fd\u3002<\/li>\n<li><strong>\u6392\u5e8f\u6548\u7387\uff1a<\/strong>COMB\u6578\u64da\u985e\u578b\u7684\u6642\u9593\u6233\u90e8\u5206\u4f7f\u5f97\u6578\u64da\u5728\u63d2\u5165\u6642\u80fd\u5920\u4fdd\u6301\u4e00\u5b9a\u7684\u6392\u5e8f\u6027\uff0c\u9019\u5c0d\u65bc\u67d0\u4e9b\u67e5\u8a62\u64cd\u4f5c\u4f86\u8aaa\u662f\u6709\u5229\u7684\u3002<\/li>\n<\/ul>\n<h2 id=\"comb%e6%95%b8%e6%93%9a%e9%a1%9e%e5%9e%8b%e7%9a%84%e7%bc%ba%e9%bb%9e-IiZLpUyUqf\">COMB\u6578\u64da\u985e\u578b\u7684\u7f3a\u9ede<\/h2>\n<ul>\n<li><strong>\u8907\u96dc\u6027\uff1a<\/strong>\u76f8\u8f03\u65bc\u50b3\u7d71\u7684\u6574\u6578\u4e3b\u9375\uff0cCOMB\u7684\u751f\u6210\u548c\u7ba1\u7406\u76f8\u5c0d\u8907\u96dc\uff0c\u53ef\u80fd\u9700\u8981\u984d\u5916\u7684\u4ee3\u78bc\u4f86\u8655\u7406\u3002<\/li>\n<li><strong>\u5b58\u5132\u7a7a\u9593\uff1a<\/strong>\u96d6\u7136COMB\u7684\u7d22\u5f15\u8f03\u5c0f\uff0c\u4f46\u5176\u672c\u8eab\u7684\u5b58\u5132\u7a7a\u9593\u4ecd\u7136\u6bd4\u6574\u6578\u4e3b\u9375\u8981\u5927\uff0c\u9019\u5728\u67d0\u4e9b\u60c5\u6cc1\u4e0b\u53ef\u80fd\u6703\u5f71\u97ff\u6027\u80fd\u3002<\/li>\n<\/ul>\n<h2 id=\"%e5%a6%82%e4%bd%95%e5%9c%a8sql-server%e4%b8%ad%e5%af%a6%e7%8f%becomb%e4%b8%bb%e9%8d%b5-IiZLpUyUqf\">\u5982\u4f55\u5728SQL Server\u4e2d\u5be6\u73feCOMB\u4e3b\u9375<\/h2>\n<p>\u5728SQL Server\u4e2d\u5be6\u73feCOMB\u4e3b\u9375\u7684\u904e\u7a0b\u76f8\u5c0d\u7c21\u55ae\u3002\u4ee5\u4e0b\u662f\u4e00\u500b\u57fa\u672c\u7684\u793a\u4f8b\uff0c\u5c55\u793a\u5982\u4f55\u5275\u5efa\u4e00\u500b\u5305\u542bCOMB\u4e3b\u9375\u7684\u8868\uff1a<\/p>\n<pre><code>CREATE TABLE ExampleTable (\n    Id UNIQUEIDENTIFIER NOT NULL PRIMARY KEY,\n    Name NVARCHAR(100) NOT NULL,\n    CreatedAt DATETIME NOT NULL DEFAULT GETDATE()\n);\n<\/code><\/pre>\n<p>\u63a5\u4e0b\u4f86\uff0c\u6211\u5011\u9700\u8981\u4e00\u500b\u51fd\u6578\u4f86\u751f\u6210COMB\u503c\uff1a<\/p>\n<pre><code>CREATE FUNCTION dbo.NewCOMB()\nRETURNS UNIQUEIDENTIFIER\nAS\nBEGIN\n    DECLARE @NewID UNIQUEIDENTIFIER;\n    SET @NewID = NEWID();\n    DECLARE @Timestamp VARBINARY(8);\n    SET @Timestamp = CONVERT(VARBINARY(8), GETDATE());\n    RETURN CAST(CONCAT(@Timestamp, @NewID) AS UNIQUEIDENTIFIER);\nEND;\n<\/code><\/pre>\n<p>\u5728\u63d2\u5165\u6578\u64da\u6642\uff0c\u6211\u5011\u53ef\u4ee5\u4f7f\u7528\u9019\u500b\u51fd\u6578\u4f86\u751f\u6210\u4e3b\u9375\uff1a<\/p>\n<pre><code>INSERT INTO ExampleTable (Id, Name)\nVALUES (dbo.NewCOMB(), 'Sample Name');\n<\/code><\/pre>\n<h2 id=\"%e7%b5%90%e8%ab%96-IiZLpUyUqf\">\u7d50\u8ad6<\/h2>\n<p>COMB\u6578\u64da\u985e\u578b\u4f5c\u70baSQL Server\u4e2d\u7684\u4e3b\u9375\u9078\u64c7\uff0c\u63d0\u4f9b\u4e86\u552f\u4e00\u6027\u548c\u6027\u80fd\u512a\u5316\u7684\u512a\u52e2\uff0c\u4f46\u540c\u6642\u4e5f\u5e36\u4f86\u4e86\u4e00\u5b9a\u7684\u8907\u96dc\u6027\u548c\u5b58\u5132\u7a7a\u9593\u7684\u8003\u91cf\u3002\u5728\u9078\u64c7\u4e3b\u9375\u6642\uff0c\u958b\u767c\u8005\u61c9\u6839\u64da\u5177\u9ad4\u7684\u61c9\u7528\u5834\u666f\u548c\u9700\u6c42\u4f86\u505a\u51fa\u660e\u667a\u7684\u6c7a\u7b56\u3002\u5c0d\u65bc\u9700\u8981\u9ad8\u53ef\u7528\u6027\u548c\u5206\u4f48\u5f0f\u7cfb\u7d71\u7684\u61c9\u7528\uff0cCOMB\u6578\u64da\u985e\u578b\u7121\u7591\u662f\u4e00\u500b\u503c\u5f97\u8003\u616e\u7684\u9078\u64c7\u3002<\/p>\n<p>\u5982\u9700\u4e86\u89e3\u66f4\u591a\u95dc\u65bc<em><a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a><\/em>\u548c<em><a href=\"https:\/\/server.hk\">\u4f3a\u670d\u5668<\/a><\/em>\u7684\u8cc7\u8a0a\uff0c\u8acb\u8a2a\u554f\u6211\u5011\u7684\u7db2\u7ad9\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u63a2\u7d22COMB\u6578\u64da\u985e\u578b\u5728SQL Server\u4e2d\u7684\u61c9\u7528\uff0c\u4e86\u89e3\u5982\u4f55\u9078\u53d6\u4e3b\u9375\u4ee5\u63d0\u5347\u6578\u64da\u5eab\u6027\u80fd\u548c\u552f\u4e00\u6027\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-59611","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/59611","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"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=59611"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/59611\/revisions"}],"predecessor-version":[{"id":59612,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/59611\/revisions\/59612"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=59611"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=59611"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=59611"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}