SQL Server提示「第 1 行 當 IDENTITY_INSERT 設置爲 OFF ...」錯誤解決方案

SQL Server提示:消息 544,級別 16,狀態 1,第 1 行 當 IDENTITY_INSERT 設置爲 OFF 時,不能爲表 'access_log' 中的標識列插入顯式值。是由於表中有主鍵或者其中有一個列使用了identity(1,1) 自增加。sql

應該:ide

set identity_insert 表名 ON
使用此命令把表的自增列設置爲ON,而後再執行插入code


 

set identity_insert access_log ON --若是表格設定了自增字段,插入數據時又想手動插入,須要打開該權限
INSERT INTO access_log
(aid,site_id,count,date)
VALUES
 (1, 1,45, '2016-05-10'),
 (2, 3,100, '2016-05-13'), 
 (3, 1,230, '2016-05-14'), 
 (4, 2,10, '2016-05-14'), 
 (5, 5,205, '2016-05-14'), 
 (6, 4,13, '2016-05-15'), 
 (7, 3,220, '2016-05-15'), 
 (8, 5,545, '2016-05-16'), 
 (9, 3,201, '2016-05-17');

set identity_insert access_log OFF--關閉
相關文章
相關標籤/搜索