RODBC Error - Cannot insert explicit value for identity column
我正在尝试使用 RODBC 包中的
1 2 3 4 | df <- DATA.frame(EmployeeID = c(NA, NA, NA), EmployeeName=c("Bob","Sue","Jane")) sqlSave(myconn, dat=df, tablename ="Employees", append = TRUE, rownames = FALSE, colnames = FALSE, verbose = TRUE, safer = TRUE, addPK = FALSE, typeInfo, varTypes, fast = TRUE, test = FALSE, nastring = NULL) |
但是,我不断收到错误
[RODBC] 更新中执行失败
23000 544 [Microsoft][ODBC SQL Server Driver][SQL Server]当 IDENTITY_INSERT 设置为 OFF 时,无法在表 \\'Employees\\' 中插入标识列的显式值。
我的表应该会自动创建 ID。什么给了?
添加这个答案,因为我找到了解决问题的黑客式解决方法。
1 | sqlQuery(myconn,"Set Identity_Insert Employees On", errors = TRUE) |
1 2 3 4 5 6 7 8 9 10 11 12 13 | sqlSave( myconn, dat=df, tablename ="Employees", append = TRUE, rownames = TRUE, colnames = FALSE, verbose = TRUE, safer = TRUE, addPK = TRUE, fast = TRUE, test = FALSE, nastring = NULL ) |
1 | sqlQuery(myconn,"Set Identity_Insert Employees Off", errors = TRUE) |