我在Microsoft SQL Server中是个新手,但对DB却不太熟悉,并且遇到以下问题。
我必须删除名为VulnerabilityReference的表内的所有记录
所以我执行了这个声明:
delete from VulnerabilityReference;
但是我收到此错误消息,并且没有从表中删除任何行:
Msg 547, Level 16, State 0, Line 1
The DELETE statement conflicted with the REFERENCE constraint "FK_AlertDocument_Reference_Reference". The conflict occurred in database "DB NAME", table "dbo.VulnerabilityAlertDocument_VulnerabilityReference", column 'VulnerabilityReferenceId'.
The statement has been terminated.
到底是什么意思?我是否必须先删除VulnerabilityAlertDocument_VulnerabilityReference表中的所有记录,然后再将记录删除到VulnerabilityReference中?
特纳克斯
安德里亚
您尝试删除的表在另一个表中具有它的主键。您必须先删除(或设置为null)其他表中的列,然后才能删除。这称为数据库参照完整性。
您可以禁用约束(如果您具有足够的权限),但是我建议您不要这样做。
要删除该其他表中所有记录的链接,可以执行以下操作:
UPDATE VulnerabilityAlertDocument_VulnerabilityReference
SET VulnerabilityReferenceId = NULL
如果AlertDocument表的该列不允许为空,则您需要DELETE
所有VulnerabilityAlertDocument_VulnerabilityReference记录等...或ALTER
将该表更改为ALLOW NULL
。确保您知道自己将要做什么...
我假设使用VulnerabilityAlertDocument_VulnerabilityReference表中的列名,显然您需要使用正确的表名和列名。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句