<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      轉:SqlServer2012自增列值突然增大1000的原因及解決方法

       

      原文鏈接:http://blog.csdn.net/phoenix36999/article/details/53304126

       

      首先排除數據回滾及增加刪除等操作。

       

      按照這篇文章SQL Server 2012 Auto Identity Column Value Jump Issue的方法,就可以解決問題了。

       

      以下是內容:

       

       

      Introduction

       

      From SQL Server 2012 version, when SQL Server instance is restarted, then table's Identity value is jumped and the actual jumped value depends on identity column data type. If it is integer (int) data type, then jump value is 1000 and if big integer (bigint), then jump value is 10000. From our application point of view, this increment is not acceptable for all the business cases specially when the value shows to the client. This is the special case/issue ships with only SQL Server 2012 and older versions have no such issue.

      從SQL Server2012版本中,當SQL Server實例重新啟動,則表的IDENTITY值跳起來,實際跳下值取決于標識列的數據類型。如果它是整數(INT)數據類型,然后跳到值是1000,如果大的整數(BIGINT),然后跳值為10000。從我們的應用程序的角度來看,這個增量在所有的商業案例中是無法接受的,特別是當值展示給客戶端時。這是特殊情況,問題僅隨SQL Server 2012,舊版本有沒有這樣的問題。

      Background

      A few days ago, our QA Engineer claims that one of our table's identity column jumped 10000. That means the last identity value of that table was 2200 now it is 12001. In our business logic is like that the value shows to the client and it will not be accepted by the client. So we must solve the issue.

      Using the Code

      The first time, we all are surprised and confused as to how it is possible? We usually do not insert any value in identity column (insert value to identity column is possible). The identity value is maintained by SQL Server itself. One of our core team members started investigation the issue and found out the solution. Now, I want to elaborate the issue and solution that was found out by my colleague.

      How to Reproduce That?

      You need to setup SQL Server 2012 and create a test database. Then create a table with auto identity column:

      create table MyTestTable(Id int Identity(1,1), Name varchar(255));
      

      Now insert 2 rows there:

      insert into MyTestTable(Name) values ('Mr.Tom');
      insert into MyTestTable(Name) values ('Mr.Jackson'); 

      You see the result:

      SELECT Id, Name FROM MyTestTable; 

       

      The result is as expected. Now just restart your SQL Server service. There are various ways in which you can do it. We did it from SQL Server management studio.

      Now, insert another 2 rows to the same table again:

      insert into MyTestTable(Name) values ('Mr.Tom2');
      insert into MyTestTable(Name) values ('Mr.Jackson2');

      Now see the result:

      SELECT Id, Name FROM MyTestTable;

      Now you see that after restarting the SQL Server 2012 instance, then identity value starts with 1002. It means it jumped 1000. Previously, I said that we also see if the data type of that identity column is bigint, then it will jump 10000.

      Is it really a bug?

      Microsoft declares it is a feature rather than a bug and in many scenarios it would be helpful. But in our case, it would not be acceptable because that number is shown to the client and the client will be surprised to see that new number after jump and the new number depends on how many times SQL Server is restarted. If it is not visible to the client, then it might be acceptable so that the number is used internally.

      Solutions  解決方法

      If we are not interested in this so called feature, then we can do two things to stop that jump.

      • Using Sequence  方法一:使用序列
      • Register -t272 to SQL Server Startup Parameter  方法二:注冊-t272到SQL Server啟動參數

      Using Sequence

      First, we need to remove Identity column from tables. Then create a sequence without cache feature and insert number from that sequence. The following is the code sample:

      CREATE SEQUENCE Id_Sequence
          AS INT
          START WITH 1
          INCREMENT BY 1
          MINVALUE 0
          NO MAXVALUE
         NO CACHE
      insert into MyTestTable values(NEXT VALUE FOR Id_Sequence, 'Mr.Tom'); 
      insert into MyTestTable values(NEXT VALUE FOR Id_Sequence, 'Mr.Jackson'); 

      Register -t272 to SQL Server Startup Parameter

      Open SQLServer configuration manager from your server. Select SQL Server 2012 instance there right client and select Properties menu. You will find a tabbed dialog window. You select start up parameters tab from there and register -t272. Then restart SQL Server 2012 instance again and see the difference:

      打開SQLServer configuration manager。左邊選擇服務。右邊在對應實例右鍵選擇屬性。點擊啟動參數。把-t272添加進去。重啟sqlserver服務。再次新增數據進行觀察。

      Points of Interest

      If too many tables contain identity column to your database and all contain existing values, then it is better to go for solution 2. Because it is a very simple solution and its scope is server wise. This means if you add SQL Server 2012 parameter -t272 there, then it will affect all your databases there. If you want to create a new database and you need auto generated number field, then you can use solution 1, that means use sequence value to a column instead of auto Identity value. There are so many articles you can find online about when you will use auto identity column when using sequence and advantages/disadvantages of each other. I hope you will read all those and take the appropriate decision.

       

      如果您的數據庫表包含太多的標識列,并且所有的表都包含現有的值,那么最好是去用解決方案2。因為它是一個非常簡單的解決方案,它的范圍是服務器。這意味著如果你添加SQL Server 2012參數- t272,然后它會影響你所有的數據庫里。

      如果你想創建一個新的數據庫,你需要自動生成的數字字段,那么你可以使用解決方案1,這意味著使用序列值的列,而不是自動識別值。

      有這么多的文章,你可以找到網上關于當你將使用自動識別列時,使用序列和優勢/劣勢的對方。我希望你會閱讀所有這些,并采取適當的決定。

      posted @ 2016-12-28 14:39  冰深  閱讀(2601)  評論(0)    收藏  舉報
      主站蜘蛛池模板: 成人免费无码不卡毛片| 日韩中av免费在线观看| 中文字幕有码日韩精品| 久久av中文字幕资源网| 一区二区中文字幕av| 2021国产精品视频网站| 风韵丰满妇啪啪区老老熟女杏吧| 一区二区和激情视频| 久久一日本道色综合久久| 亚洲成a人无码av波多野| 精品无套挺进少妇内谢| 波多野结衣乳喷高潮视频| 亚洲悠悠色综合中文字幕| 铁岭市| 白嫩少妇无套内谢视频| 国产亚洲人成网站在线观看 | 国产一区二区不卡91| 国产成人亚洲无码淙合青草| 国产精品一区二区三区污| 99久久久无码国产精品免费 | 国产女人喷潮视频免费| 午夜免费无码福利视频麻豆| 国产成人a在线观看视频| 青青草一区在线观看视频| 人妻av资源先锋影音av资源| 国产成人片无码视频在线观看| 国产日韩乱码精品一区二区 | 亚洲精品国产av成人网| 免费现黄频在线观看国产| 亚洲另类无码一区二区三区| 国产精品一区二区久久岳| 国产精品青草久久久久福利99| 亚洲久久色成人一二三区| 七台河市| 色欲国产精品一区成人精品| 成人福利国产午夜AV免费不卡在线 | 成年无码av片完整版| 欧美18videosex性欧美tube1080 | 免费国产一区二区不卡| 亚洲一区成人av在线| 亚洲国产精品高清线久久|