DELETE语句 [英] The DELETE statement
本文介绍了DELETE语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个错误
DELETE语句与REFERENCE约束FK_Stores_Employees冲突。冲突发生在数据库MultiStore,表dbo.Stores ,列'EmployeeID'。
声明已被终止。
我需要做什么?
i have this error
"
The DELETE statement conflicted with the REFERENCE constraint "FK_Stores_Employees". The conflict occurred in database "MultiStore", table "dbo.Stores", column 'EmployeeID'.
The statement has been terminated.
"
what i have to do?
推荐答案
您尝试删除的员工记录目前与商店中的一个或多个记录相关联
table。
更新商店
表中的受影响记录,以将其与其他员工关联;或者,如果EmployeeID
列允许Null
值,请将其设置为Null
;或删除关联的商店记录。
The employee record you're trying to delete is currently associated with one or more records in theStores
table.
Either update the affected records in theStores
table to associate them with a different employee; or, if theEmployeeID
column allowsNull
values, set it toNull
; or delete the associated store records.
我怀疑您在EmployeeID上启用了参照完整性,以确保商店不会引用不存在的员工 - 然后您很可能试图删除一名员工。
0)删除通常不是一个好主意,请尝试设置状态。
1)或者,在删除员工之前删除商店中的引用。
2)这可以通过启用级联删除来完成,但这不是一个好主意。
不删除记录(例如员工记录)的原因是您了解企业中发生的事件。通过记录开始和结束日期,您可以轻松查询Bob何时为我们工作以及在哪个商店工作?等内容。 - 如果删除Bob记录,则无法实现。您会发现这就是商业软件的工作方式。即使这是一个学生项目,请这样做以养成习惯 - 它也应该导致更好的成绩。
I suspect that you have referential integrity enabled on EmployeeID to ensure that a store doesn't refer to a non-existent employee -- and then you are likely trying to delete an employee.
0) Deleting is not generally a good idea, try setting a status instead.
1) Or, remove the reference in Stores before deleting the employee.
2) This may be done by enabling cascaded deletes, but that is not a very good idea.
The reason not to delete records (such as employee records) is so you have a history of what happened in the enterprise. With a record of start and end dates you can easily query things like "when did Bob work for us and in what store?" -- if you delete the Bob record you have no way to achieve that. You will find that this is how business software works. Even if this is a student project, please do it this way to get in the habit -- it should lead to a better grade as well.
由于数据被引用并充当另一个表的外键,你需要更改依赖表的值,然后尝试删除记录
Since the data is being referenced and acts as a foreign key for another table, you need to change the value for the dependent table and then try to delete the record
这篇关于DELETE语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文