SQLServer,僅當使用了列列表並且 IDENTITY_INSERT 為 ON 時,才能為表xx中的識別欄位指定顯式值,sqlserveridentity

來源:互聯網
上載者:User

SQLServer,僅當使用了列列表並且 IDENTITY_INSERT 為 ON 時,才能為表xx中的識別欄位指定顯式值,sqlserveridentity


情景: 如果此表的主鍵或者其中有一個列使用了  IDENTITY(1,1) 自增長時,但又想手動為此列指定值時,當用如下解決方案:

set identity_insert 表名 ON

使用此命令把表的自增列設定為ON

然後使用 :

SELECT 3,0,'阿道夫',141,0,2,'133','09 24 2008  3:23PM','133','09 24 2008  3:23PM',0,'NULL'

的方式,插入資料(是使用Select的方式,不能用Insert into).


插入完成以後,再把列設定為OFF


set identity_insert [agent_ctm_shopgroup_tbl] OFF


相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.