我有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