简体   繁体   English

在SQL Server 2014中删除,同时保持引用完整性

[英]DELETE in SQL Server 2014 while maintaining referential integrity

My instructor has asked us to DELETE a row from a referenced table. 我的老师要求我们从引用表中删除一行。 The question is: Delete operator 4. Don't forget referential integrity, but do not delete any trips or vehicles. 问题是:删除运算符4.不要忘记参照完整性,但不要删除任何行程或车辆。

I understand cascade delete and referential integrity but cannot wrap my mind around this. 我了解级联删除和参照完整性,但无法对此全神贯注。 To clarify, I know that Cascade delete would allow for the removal of the operator but would also delete the trips. 为了澄清,我知道级联删除将允许删除操作员,但也将删除行程。 He does not want the trips or any other referencing table to change. 他不希望行程或任何其他引用表发生变化。

I though it might be a trick question and just make all the fields of Operator 4 Null but they require a value so that's a no go. 我虽然可能是一个棘手的问题,只是将Operator 4的所有字段都设为Null,但是它们需要一个值,所以这是不可行的。

Operator 4 is referenced by a table named Runs. 名为Runs的表引用了运算符4。 The Runs table is referenced by a table named Schedule. Runs表由名为Schedule的表引用。 The Schedule table is referenced by a table named Trips. Schedule表由名为Trips的表引用。

How can I DELETE operator 4 while maintaining referential integrity or is there an angle I'm not looking at it from. 我如何在保持引用完整性的同时删除运算符4,或者我是不是从某个角度来看呢?

Thank you in advance. 先感谢您。

如果FK col可为空,则可以将其设置为null并删除以前引用的记录。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM