{"id":298,"date":"2012-03-20T01:35:49","date_gmt":"2012-03-20T01:35:49","guid":{"rendered":"http:\/\/ahsiu.com\/?p=298"},"modified":"2012-03-20T01:35:49","modified_gmt":"2012-03-20T01:35:49","slug":"sql-server%e4%b8%ad%e7%9a%84%e8%87%aa%e5%a2%9e%e9%97%ae%e9%a2%98","status":"publish","type":"post","link":"https:\/\/blog.xiunian.wang\/?p=298","title":{"rendered":"sql server\u4e2d\u7684\u81ea\u589e\u95ee\u9898"},"content":{"rendered":"<h1 id=\"question-title\">sql server 2005 \u5982\u4f55\u8bbe\u7f6eint\u578b\u6570\u636e\u81ea\u589e\uff0c\u53c8\u5982\u4f55\u63d2\u5165\u4e00\u6761\u8bb0\u5f55\uff1f<\/h1>\n<div id=\"blog_text\">\n<p>SQL Server \u901a\u8fc7IDENTITY\u00a0\u6765\u8bbe\u7f6e<\/p>\n<p>\u53c2\u6570\u67092\u4e2a\uff0c\u4e00\u4e2a\u662f\u201c\u521d\u59cb\u503c\u201d\u4e00\u4e2a\u662f\u201c\u589e\u91cf\u201d\u3002<\/p>\n<p>&nbsp;<\/p>\n<p>1&gt; CREATE TABLE test_create_tab2 (<\/p>\n<p>2&gt;\u00a0\u00a0\u00a0id\u00a0\u00a0\u00a0INT <strong>\u00a0IDENTITY(1, 1)\u00a0<\/strong>\u00a0PRIMARY KEY,<\/p>\n<p>3&gt;\u00a0\u00a0\u00a0val\u00a0\u00a0VARCHAR(10)<\/p>\n<p>4&gt; );<\/p>\n<p>5&gt; go<\/p>\n<p>&nbsp;<\/p>\n<p>1&gt; INSERT INTO test_create_tab2(val) VALUES (&#8216;NO id&#8217;);<\/p>\n<p>2&gt; go<\/p>\n<p>&nbsp;<\/p>\n<p>\u9ed8\u8ba4\u60c5\u51b5\u4e0bINSERT\u8bed\u53e5\u4e2d\uff0c\u4e0d\u80fd\u5bf9IDENTITY\u00a0\u7684\u5b57\u6bb5\u8fdb\u884c\u8d4b\u503c\u3002<\/p>\n<p>&nbsp;<\/p>\n<p>1&gt; INSERT INTO test_create_tab2(id, val) VALUES (6, &#8216;id no use&#8217;);<\/p>\n<p>2&gt; go<\/p>\n<p>\u6d88\u606f544\uff0c\u7ea7\u522b16\uff0c\u72b6\u60011\uff0c\u670d\u52a1\u5668HOME-BED592453CSQLEXPRESS\uff0c\u7b2c1\u884c<\/p>\n<p>\u5f53IDENTITY_INSERT\u8bbe\u7f6e\u4e3aOFF\u65f6\uff0c\u4e0d\u80fd\u4e3a\u8868&#8217;test_create_tab2&#8217;\u4e2d\u7684\u6807\u8bc6\u5217\u63d2\u5165\u663e\u5f0f\u503c\u3002<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>1&gt; INSERT INTO test_create_tab2(val) VALUES (&#8216;A&#8217;);<\/p>\n<p>2&gt; INSERT INTO test_create_tab2(val) VALUES (&#8216;B&#8217;);<\/p>\n<p>3&gt; INSERT INTO test_create_tab2(val) VALUES (&#8216;C&#8217;);<\/p>\n<p>4&gt; INSERT INTO test_create_tab2(val) VALUES (&#8216;D&#8217;);<\/p>\n<p>5&gt; go<\/p>\n<p>&nbsp;<\/p>\n<p>1&gt; SELECT * FROM test_create_tab2;<\/p>\n<p>2&gt; go<\/p>\n<p>id\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0val<\/p>\n<p>&#8212;&#8212;&#8212;&#8211; &#8212;&#8212;&#8212;-<\/p>\n<p>1 NO id<\/p>\n<p>2 A<\/p>\n<p>3 B<\/p>\n<p>4 C<\/p>\n<p>5 D<\/p>\n<p>&nbsp;<\/p>\n<p>(5\u884c\u53d7\u5f71\u54cd)<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>\u5f53IDENTITY\u5217\u4e2d\u95f4\u7684\u6570\u636e\u88ab\u5220\u9664\uff0c\u9020\u6210\u6570\u636e\u4e0d\u8fde\u7eed\u7684\u65f6\u5019\u3002<\/p>\n<p>\u53ef\u4ee5\u901a\u8fc7<strong>SET IDENTITY_INSERT\u00a0<\/strong><strong>\u8868\u540dON\/OFF<\/strong>\u8bed\u53e5\u6765\u5141\u8bb8\/\u7981\u6b62\u5bf9IDENTITY\u5217\u8fdb\u884c\u663e\u5f0f\u7684\u63d2\u5165\u52a8\u4f5c\u3002<\/p>\n<p>&nbsp;<\/p>\n<p>&#8211;\u5220\u9664\u4e00\u4e2a\u6570\u636e\uff0c\u9020\u6210\u6570\u636e\u4e0d\u8fde\u7eed.<\/p>\n<p>1&gt; DELETE FROM test_create_tab2 WHERE id = 3;<\/p>\n<p>2&gt; go<\/p>\n<p>&nbsp;<\/p>\n<p>(1\u884c\u53d7\u5f71\u54cd)<\/p>\n<p>&nbsp;<\/p>\n<p>&#8211;\u5141\u8bb8\u5c06\u663e\u5f0f\u503c\u63d2\u5165\u8868\u7684\u6807\u8bc6\u5217\u4e2d<\/p>\n<p>1&gt; <strong>SET IDENTITY_INSERT<\/strong> test_create_tab2 <strong>ON<\/strong><\/p>\n<p>2&gt; go<\/p>\n<p>1&gt; INSERT INTO test_create_tab2(id, val) VALUES (3, &#8216;id is use&#8217;);<\/p>\n<p>2&gt; go<\/p>\n<p>&nbsp;<\/p>\n<p>(1\u884c\u53d7\u5f71\u54cd)<\/p>\n<p>&nbsp;<\/p>\n<p>&#8211;\u4e0d\u5141\u8bb8\u5c06\u663e\u5f0f\u503c\u63d2\u5165\u8868\u7684\u6807\u8bc6\u5217\u4e2d<\/p>\n<p>1&gt;\u00a0\u00a0<strong>SET IDENTITY_INSERT<\/strong> test_create_tab2 <strong>OFF<\/strong><\/p>\n<p>2&gt; go<\/p>\n<p>1&gt; SELECT * FROM test_create_tab2;<\/p>\n<p>2&gt; go<\/p>\n<p>id\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0val<\/p>\n<p>&#8212;&#8212;&#8212;&#8211; &#8212;&#8212;&#8212;-<\/p>\n<p>1 NO id<\/p>\n<p>2 A<\/p>\n<p>3 id is use<\/p>\n<p>4 C<\/p>\n<p>5 D<\/p>\n<p>&nbsp;<\/p>\n<p>(5\u00a0\u884c\u53d7\u5f71\u54cd)<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p><strong>IDENTITY\u7684\u91cd\u7f6e<\/strong><\/p>\n<p>\u65b9\u6848\u4e00\uff1a\u901a\u8fc7truncate table\u00a0\u5904\u7406<\/p>\n<p>[\u6b64\u547d\u4ee4\u5c06\u5220\u9664\u8868\u4e2d\u6240\u6709\u7684\u6570\u636e,\u4f7f\u7528\u524d\u4f60\u9700\u8981\u786e\u8ba4\u4f60\u662f\u5426\u8981\u505a\u8fd9\u4e2a\u64cd\u4f5c. \u5982\u679c\u4e0d\u5e0c\u671b\u4fee\u6539\u8868\u6570\u636e\u7684,\u8bf7\u91c7\u7528\u65b9\u6848\u4e8c]<\/p>\n<p>1&gt; truncate table\u00a0\u00a0test_create_tab2;<\/p>\n<p>2&gt; go<\/p>\n<p>1&gt; INSERT INTO test_create_tab2(val) VALUES (&#8216;NO id&#8217;);<\/p>\n<p>2&gt; go<\/p>\n<p>&nbsp;<\/p>\n<p>(1\u884c\u53d7\u5f71\u54cd)<\/p>\n<p>1&gt; select * from test_create_tab2;<\/p>\n<p>2&gt; go<\/p>\n<p>id\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0val<\/p>\n<p>&#8212;&#8212;&#8212;&#8211; &#8212;&#8212;&#8212;-<\/p>\n<p>1 NO id<\/p>\n<p>&nbsp;<\/p>\n<p>(1\u884c\u53d7\u5f71\u54cd)<\/p>\n<p>&nbsp;<\/p>\n<p>\u65b9\u6848\u4e8c\uff1a\u4f7f\u7528DBCC<\/p>\n<p>1&gt; select * from test_create_tab2;<\/p>\n<p>2&gt; go<\/p>\n<p>id\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0val<\/p>\n<p>&#8212;&#8212;&#8212;&#8211; &#8212;&#8212;&#8212;-<\/p>\n<p>2 NO id<\/p>\n<p>&nbsp;<\/p>\n<p>(1\u884c\u53d7\u5f71\u54cd)<\/p>\n<p>1&gt; delete from test_create_tab2;<\/p>\n<p>2&gt; go<\/p>\n<p>&nbsp;<\/p>\n<p>(1\u884c\u53d7\u5f71\u54cd)<\/p>\n<p>&nbsp;<\/p>\n<p>\u67e5\u770b\u5f53\u524dID\u3002<\/p>\n<p>1&gt; <strong>DBCC CHECKIDENT<\/strong>(&#8216;test_create_tab2&#8217;, <strong>NORESEED<\/strong>)<\/p>\n<p>2&gt; go<\/p>\n<p>\u68c0\u67e5\u6807\u8bc6\u4fe1\u606f:\u5f53\u524d\u6807\u8bc6\u503c&#8217;2&#8217;\uff0c\u5f53\u524d\u5217\u503c&#8217;2&#8217;\u3002<\/p>\n<p>DBCC\u6267\u884c\u5b8c\u6bd5\u3002\u5982\u679cDBCC\u8f93\u51fa\u4e86\u9519\u8bef\u4fe1\u606f\uff0c\u8bf7\u4e0e\u7cfb\u7edf\u7ba1\u7406\u5458\u8054\u7cfb\u3002<\/p>\n<p>&nbsp;<\/p>\n<p>\u91cd\u7f6eID<\/p>\n<p>1&gt; <strong>DBCC CHECKIDENT<\/strong>(&#8216;test_create_tab2&#8217;, <strong>RESEED<\/strong>, 100)<\/p>\n<p>2&gt; go<\/p>\n<p>\u68c0\u67e5\u6807\u8bc6\u4fe1\u606f:\u5f53\u524d\u6807\u8bc6\u503c&#8217;2&#8217;\uff0c\u5f53\u524d\u5217\u503c&#8217;100&#8217;\u3002<\/p>\n<p>DBCC\u6267\u884c\u5b8c\u6bd5\u3002\u5982\u679cDBCC\u8f93\u51fa\u4e86\u9519\u8bef\u4fe1\u606f\uff0c\u8bf7\u4e0e\u7cfb\u7edf\u7ba1\u7406\u5458\u8054\u7cfb\u3002<\/p>\n<p>1&gt; INSERT INTO test_create_tab2(val) VALUES (&#8216;NO id&#8217;);<\/p>\n<p>2&gt; go<\/p>\n<p>&nbsp;<\/p>\n<p>(1\u884c\u53d7\u5f71\u54cd)<\/p>\n<p>1&gt; select * from test_create_tab2;<\/p>\n<p>2&gt; go<\/p>\n<p>id\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0val<\/p>\n<p>&#8212;&#8212;&#8212;&#8211; &#8212;&#8212;&#8212;-<\/p>\n<p>101 NO id<\/p>\n<p>&nbsp;<\/p>\n<p>(1\u884c\u53d7\u5f71\u54cd)<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>IDENTITY\u53ea\u80fd\u5728\u5982\u4e0b\u60c5\u51b5\u4e0b\u5efa\u7acb:<\/p>\n<p>\u5728\u521b\u5efa\u8868\u65f6\u521b\u5efa\u65b0\u7684IDENTITY\u5217<\/p>\n<p>\u5728\u73b0\u6709\u8868\u4e2d\u521b\u5efa\u65b0\u7684IDENTITY\u5217<\/p>\n<p>\u4e0d\u80fd\u00a0\u628a\u5df2\u7ecf\u5b58\u5728\u7684\u5217,\u4fee\u6539\u4e3aIDENTITY\u5217<\/p>\n<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;\u534e\u4e3d\u5206\u5272\u7ebf&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<\/p>\n<p>\u4eca\u5929<strong><a href=\"http:\/\/www.aspbc.com\/tech\/showclass.asp?id=7\" target=\"_blank\">sql server<\/a><\/strong>\u7684\u5b58\u50a8\u8fc7\u7a0b\u5e2e\u4e86\u6211\u5927\u5fd9\u554a,\u6216\u8bb8\u4f1a\u56e0\u4e3a\u4eca\u5929\u8ba9\u6211\u6162\u6162\u559c\u6b22\u4e0a\u5b58\u50a8\u8fc7\u7a0b\u5427\u3002<\/p>\n<p>\u5728\u4f7f\u7528\u6570\u636e\u5e93\u7684\u65f6\u5019,\u96be\u514d\u8981\u5728\u4f7f\u7528\u8fc7\u7a0b\u4e2d\u8fdb\u884c\u5220\u9664\u7684\u64cd\u4f5c,\u5982\u679c\u662f\u4f7f\u7528int\u7c7b\u578b\u7684\u5b57\u6bb5,\u4ee4\u5176\u81ea\u589e\u957f,\u8fd9\u662f\u4e2a\u6700\u7b80\u5355\u7684\u529e\u6cd5,\u4f46\u662f\u540e\u679c\u4f1a\u6709\u4e9b\u4e0d\u662f\u4f60\u60f3\u8981\u7684!\u770b\u4e0b\u8fd9\u4e2aDemo:<br \/>\n1.\u5efa\u7acb\u8fd9\u6837\u7684\u7b80\u5355\u7684\u8868Test.<br \/>\n<img decoding=\"async\" src=\"http:\/\/www.aspbc.com\/uploadfile\/kind\/20111031\/20111031822504772815.jpg\" alt=\"\" \/><br \/>\n2.\u8bbe\u7f6e\u5b57\u6bb5id\u7684\u81ea\u589e.<br \/>\n<img decoding=\"async\" src=\"http:\/\/www.aspbc.com\/uploadfile\/kind\/20111031\/20111031822584114734.jpg\" alt=\"\" \/><br \/>\n3.\u8868\u6dfb\u52a0\u6570\u636e<br \/>\ninsert into Test(name) values(&#8216;TestName&#8217;)<br \/>\ninsert into Test(name) values(&#8216;TestName&#8217;)<br \/>\ninsert into Test(name) values(&#8216;TestName&#8217;)<br \/>\n4.\u4f60\u4f1a\u770b\u5230<br \/>\n<img decoding=\"async\" src=\"http:\/\/www.aspbc.com\/uploadfile\/kind\/20111031\/20111031823243447864.jpg\" alt=\"\" \/><br \/>\n5.\u5728\u8fd9\u91cc\u6211\u4eec\u5220\u9664id\u4e3a2\u7684\u884c.\u5c31\u53ea\u5269\u4e0b\u4e86id\u4e3a1\u548cid\u4e3a3\u7684\u4e24\u884c\u6570\u636e\u4e86.(\u4e0d\u4e0a\u56fe\u4e86)<br \/>\n6.\u518d\u6dfb\u52a0\u4e00\u6761\u6570\u636e.<br \/>\ninsert into Test(name) values(&#8216;TestName&#8217;)<br \/>\n\u6211\u4eec\u4f1a\u53d1\u73b0\u8fd9\u6216\u8bb8\u4e0d\u662f\u6211\u4eec\u60f3\u8981\u7684\u7ed3\u679c\u4e86<br \/>\n<img decoding=\"async\" src=\"http:\/\/www.aspbc.com\/uploadfile\/kind\/20111031\/20111031823335455066.jpg\" alt=\"\" \/><br \/>\n\u4e3a\u4ec0\u4e48\u6ca1\u6709id\u4e3a2\u7684\u5462?\u4e4b\u540e\u4efb\u4f60\u6b7b\u547d\u7684\u52a0,\u4e5f\u4e0d\u4f1a\u6709id\u4e3a2\u7684\u6570\u636e\u884c\u4e86!<br \/>\n\u8fd9\u6837\u7684\u8bbe\u8ba1\u56fa\u7136\u65b9\u4fbf,\u4f46\u662f\u9b54\u9b3c\u5728\u4e8e\u7ec6\u8282,\u8fd9\u7bc7\u535a\u5ba2\u5c31\u662f\u4e3a\u4e86\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\u8ba9\u6211\u4eec\u91cd\u65b0\u89c1\u5230id\u4e3a2\u7684\u6570\u636e\u884c(\u8fd9\u91cc\u987a\u4fbf\u6539\u8fdb\u4e00\u4e0b,\u8ba9\u7ed3\u679c\u4e0d\u53ea\u662f\u663e\u793aid\u4e3a2\u8fd9\u6837\u7684int,\u5047\u5982\u6709\u4e00\u5929\u6211\u4eec\u7684\u5404\u6237\u8981\u6c42\u6211\u4eec\u4ed6\u4eec\u8981\u4e00\u4e2a5\u4f4d\u6570\u7684id\u53f7\u5417,\u4ece00000\u5f00\u59cb,OK,\u8fd9\u6ca1\u95ee\u9898)<br \/>\n1.\u4e3b\u89d2\u767b\u573a,\u5b58\u50a8\u8fc7\u7a0b\u7ec8\u4e8e\u6d3e\u4e0a\u4e86\u7528\u573a\u4e86<\/p>\n<blockquote>\n<pre>Create procedure [dbo].[insertName](@name nvarchar(50)) \nas\nbegin\n     declare @i int\n     set @i=1 \n     while(@i&lt;10000) \n     begin\n       if exists(select convert(int,id) from numbertest where convert(int,id)=@i) \n       begin\n       set @i=@i+1 \n       continue\n       end\n       else\n       begin\n       insert numbertest values(right('0000'+convert(varchar(5),@i),5),@name)\n       --\u8fd9\u91cc\u7684\u4e24\u4e2a\u6570\u5b57'5' \u5c31\u662f\u6211\u4eec\u8981\u8bbe\u7f6e\u7684id\u957f\u5ea6\n        break\n     end\n   end\nend<\/pre>\n<\/blockquote>\n<p>2.\u7528SQL \u8bed\u53e5\u8c03\u7528\u8fd9\u4e2a\u5b58\u50a8\u8fc7\u7a0b<br \/>\nexecute insertName Test<br \/>\n\u4f60\u53ef\u4ee5\u72c2\u6309\u51e0\u6b21,\u51e0\u5341\u6b21,\u51e0\u767e\u6b21,\u6211\u4eec\u8981\u7684\u6570\u636e\u52a0\u8fdb\u53bb\u4e86,<br \/>\n<img decoding=\"async\" src=\"http:\/\/www.aspbc.com\/uploadfile\/kind\/20111031\/2011103182493550723.jpg\" alt=\"\" \/><br \/>\n\u6211\u4eec\u53ef\u4ee5\u5220\u9664\u6307\u5b9a\u7684id\u6570\u636e\u884c,\u5f53\u6211\u4eec\u518d\u6b21\u8fdb\u884c\u6dfb\u52a0\u7684\u65f6\u5019,\u4e4b\u524d\u88ab\u5220\u6389\u7684id\u884c,\u5c06\u4f1a\u88ab\u6211\u4eec\u65b0\u6dfb\u52a0\u7684\u6570\u636e\u6240\u8986\u76d6,\u8fd9\u6837id\u5c31\u90fd\u53ef\u4ee5\u8fde\u63a5\u8d77\u6765\u4e86.<br \/>\n\u54e6,\u5bf9\u4e86,\u8fd8\u6ca1\u6709\u8bf4\u5982\u4f55\u663e\u793a\u7684\u662f &#8216;0&#8217; \u5f00\u5934\u7684\u5462?\u8fd9\u4e2a\u7b80\u5355,\u5c06id\u7684\u6570\u636e\u7c7b\u578b\u8bbe\u7f6e\u4e3anvarchar(5),\u5c31\u662f\u8fd9\u4e48\u7b80\u5355!\u5475\u5475!<br \/>\n\u603b\u7ed3:<br \/>\n\u8fd9\u91cc\u6211\u4eec\u8c03\u7528\u4e86\u5b58\u50a8\u8fc7\u7a0b,\u5b58\u50a8\u8fc7\u7a0b\u4e0d\u5b9c\u591a\u7528,\u4f46\u662f\u6709\u7684\u65f6\u5019\u8fd8\u771f\u662f\u7528\u8d77\u6765\u5f88\u65b9\u4fbf,\u672c\u6587\u7ae0\u5bf9\u4e8e\u521a\u521a\u5de5\u4f5c\u7684\u7ae5\u978b\u4eec\u5e94\u8be5\u8fd8\u662f\u6709\u70b9\u5e2e\u52a9\u7684\u5427,\u597d\u597d\u5b66\u4e60\u5427,\u751f\u6d3b\u5f88\u7f8e\u597d!<br \/>\n\u5982\u91ca\u91cd\u8d1f\u7684\u611f\u89c9\u554a,\u7ec8\u4e8e\u641e\u5b9a\u4e00\u4e2a\u95ee\u9898\u3002<br \/>\n\u5176\u5b9e\u8fd8\u6709\u4e00\u4e2a\u65b9\u6cd5\u4e5f\u53ef\u4ee5\u89e3\u51b3\uff1a\u5c31\u662f\u5148\u5c06ID\u5b57\u6bb5\u5220\u9664\uff0c\u518d\u91cd\u65b0\u5efa\u4e00\u4e2a\u3002<\/p>\n<p>\u867d\u7136\u4f5c\u8005\u4e3a\u6211\u4eec\u89e3\u51b3\u4e86\u4e00\u4e2a\u5927\u9ebb\u70e6\uff0c\u5728\u6b64\u5bf9\u4f5c\u8005\u8868\u793a\u611f\u8c22\u3002<br \/>\n\u4f46\u662f\u8fd8\u662f\u5bf9\u4f5c\u8005\u6709\u70b9\u770b\u6cd5\uff1a\u6570\u636e\u5e93\u662f\u7528\u6765\u5b58\u50a8\u6570\u636e\u7684\u5730\u65b9\uff0c\u81f3\u4e8eID\u5b57\u6bb5\u662f\u5426\u8981\u6309\u987a\u5e8f\u7684\u81ea\u52a8\u589e\u91cf\u5b57\u6bb5\uff0c\u6ca1\u6709\u4eba\u5728\u4e4e\u8fd9\u4e2a\uff0c\u4e5f\u6ca1\u6709\u4eba\u53bb\u770b\u8fd9\u4e2a\uff0c\u53ea\u8981\u524d\u53f0\u80fd\u591f\u5b8c\u6210\u60f3\u8981\u7684\u529f\u80fd\u5c31\u884c\u4e86\uff0c\u6ca1\u6709\u5fc5\u8981\u82b1\u8fd9\u4e48\u591a\u65f6\u95f4\u53bb\u89e3\u51b3\u8fd9\u4e2a\u65b9\u6cd5\uff0c\u5927\u5bb6\u89c9\u5f97\u6709\u8fd9\u4e2a\u5fc5\u8981\u5417\uff1f<\/p>\n<p>&nbsp;<\/p>\n<p>\u6765\u6e90 aspbc.com<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>sql server 2005 \u5982\u4f55\u8bbe\u7f6eint\u578b\u6570\u636e\u81ea\u589e\uff0c\u53c8\u5982\u4f55\u63d2\u5165\u4e00\u6761\u8bb0\u5f55\uff1f SQL Server \u901a\u8fc7IDENTITY\u00a0\u6765\u8bbe\u7f6e \u53c2\u6570\u67092\u4e2a\uff0c\u4e00\u4e2a\u662f\u201c\u521d\u59cb\u503c\u201d\u4e00\u4e2a\u662f\u201c\u589e\u91cf\u201d\u3002 &nbsp; 1&gt; CREATE TABLE test_create_tab2 ( 2&gt;\u00a0\u00a0\u00a0id\u00a0\u00a0\u00a0INT \u00a0IDENTITY(1, 1)\u00a0\u00a0PRIMARY KEY, 3&gt;\u00a0\u00a0\u00a0val\u00a0\u00a0VARCHAR(10) 4&gt; ); 5&gt; go &nbsp; 1&gt; INSERT INTO test_create_tab2(val) VALUES (&#8216;NO id&#8217;); 2&gt; go &nbsp; \u9ed8\u8ba4\u60c5\u51b5\u4e0bINSERT\u8bed\u53e5\u4e2d\uff0c\u4e0d\u80fd\u5bf9IDENTITY\u00a0\u7684\u5b57\u6bb5\u8fdb\u884c\u8d4b\u503c\u3002 &nbsp; 1&gt; INSERT INTO test_create_tab2(id, val) VALUES (6, &#8216;id no use&#8217;); 2&gt; go \u6d88\u606f544\uff0c\u7ea7\u522b16\uff0c\u72b6\u60011\uff0c\u670d\u52a1\u5668HOME-BED592453CSQLEXPRESS\uff0c\u7b2c1\u884c \u5f53IDENTITY_INSERT\u8bbe\u7f6e\u4e3aOFF\u65f6\uff0c\u4e0d\u80fd\u4e3a\u8868&#8217;test_create_tab2&#8217;\u4e2d\u7684\u6807\u8bc6\u5217\u63d2\u5165\u663e\u5f0f\u503c\u3002 &nbsp; &nbsp; 1&gt; INSERT INTO &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/blog.xiunian.wang\/?p=298\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;sql server\u4e2d\u7684\u81ea\u589e\u95ee\u9898&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,5],"tags":[],"_links":{"self":[{"href":"https:\/\/blog.xiunian.wang\/index.php?rest_route=\/wp\/v2\/posts\/298"}],"collection":[{"href":"https:\/\/blog.xiunian.wang\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.xiunian.wang\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.xiunian.wang\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.xiunian.wang\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=298"}],"version-history":[{"count":0,"href":"https:\/\/blog.xiunian.wang\/index.php?rest_route=\/wp\/v2\/posts\/298\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.xiunian.wang\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=298"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.xiunian.wang\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=298"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.xiunian.wang\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=298"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}