[英]Cannot insert explicit value for identity column in table when player is created
我收到以下錯誤消息:
{returnResult=Cannot insert explicit value for identity column in table 'player' when IDENTITY_INSERT is set to OFF.;Result=Cannot insert explicit value for identity column in table 'player' when IDENTITY_INSERT is set to OFF.;}
我目前正在嘗試在每次創建新玩家時自動增加玩家表中的player_id。 我在Windows SQL Server Management Studio中進行了設置。
我的查詢應該是什么樣?
INSERT INTO player (player_id, player_type_id)
VALUES('','1')
我有一個手動值,但是我希望user_id每次創建時都是唯一的。 所有幫助,不勝感激!
您必須設置身份插入(即,如果您要提供自己的身份值而不是要求MYSQL為您生成一個),
SET IDENTITY_INSERT Table1 ON
然后通過為該列提供自己的值來執行查詢..
然后關閉它。.(因為您只希望完成一次手動插入)
SET IDENTITY_INSERT Table1 OFF
如果您已正確地將player_id
字段設置為自動遞增,則只需將該列保留在INSERT
語句之外,而只需提供其他值即可。
INSERT INTO player (player_type_id)
VALUES('1')
如果您認為您的列當前未設置為自動遞增,請查看this 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.