我有2个表:A和BDELETE FROM表A和B的多条记录与一个FK表B
A包含以下几列:
Id [uniqueIdentifier] -PK
checkpointId [numeric(20,0)]
B包含以下内容:
Id [uniqueIdentifier] – PK
A_id (FK, uniqueIdentifier)
B具有从A_ID柱(FK)
问题至A的引用: 我想从表A中删除所有的记录,他们的checkpoint_id是小于X
delete from CheckpointStorageObject where checkpointIdentifierIdentifier <= 1000
但我不能这样做,因为"The primary key value cannot be deleted because references to this key still exist"
我试过的B表先删除没有加入:
DELETE FROM CheckpointToProtectionGroup
WHERE EXIST (SELECT * from CheckpointStorageObject
WHERE CheckpointStorageObject.CheckpointIdentifierIdentifier <= 1000)
但它没有奏效。
我该怎么办? 是否可以使用一个执行命令从两个表中删除?
结果删除的记录可能非常大 - 每张表中超过30K条记录。
我editted到存在EXIST – Haimon 2012-08-07 14:04:16