SQL Server提示:消息 544,级别 16,状态 1,第 1 行 当 IDENTITY_INSERT 设置为 OFF 时,不能为表 'access_log' 中的标识列插入显式值。是因为表中有主键或者其中有一个列使用了identity(1,1) 自增长。
应该:
set identity_insert 表名 ON
使用此命令把表的自增列设置为ON,然后再执行插入
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--关闭
来源:oschina
链接:https://my.oschina.net/u/2910125/blog/751182