【发布时间】:2016-10-17 19:07:13
【问题描述】:
我在运行 CSV SQL 批量插入时遇到错误。我收到以下错误消息:
(25000 row(s) affected)
Msg 547, Level 16, State 0, Line 13
The INSERT statement conflicted with the FOREIGN KEY constraint "fk_Employee_Store". The conflict occurred in database "SkysDoggieDaycareDB", table "dbo.Store", column 'StoreID'.
The statement has been terminated.
(1000 row(s) affected)
Msg 547, Level 16, State 0, Line 13
The INSERT statement conflicted with the FOREIGN KEY constraint "fk_Employee_Service_Emp". The conflict occurred in database "SkysDoggieDaycareDB", table "dbo.Employee", column 'EmployeeID'.
The statement has been terminated.
StoreID 和 EmployeeID 字段是在这些插入语句之前在 Store 和 Employee 表中创建的。我不确定我做错了什么。有什么想法吗?
【问题讨论】:
-
使用导入向导将 csv 文件导入临时表。然后将 ID 与父表进行比较以查看是否缺少任何 ID。
标签: sql-server foreign-keys bulkinsert