多対多の関係にある 3 つのテーブルがあります。すなわち:
Create Table Product(ProductId number(18,0) NOT NULL);
Create Table Customer(CustomerId number(18,0) NOT NULL);
Create Table CustomerProduct(CustomerId number(18,0) NOT NULL,ProductId number(18,0) NOT NULL);
CustomerProduct テーブルは Product テーブルと Customer テーブルの両方を参照しているためです。CustomerProduct テーブルからデータを削除しようとしています。
私は次のようなものしか見つけることができません:
DELETE FROM
(
SElECT CustomerProduct.* FROM CustomerProduct
INNER JOIN Product ON Product.ProductId = CustomerProduct.ProductId
INNER JOIN Customer ON Customer.CustomerId = CustomerProduct.CustomerId
WHERE Product.ProductId = 1 AND Customer.CustomerId = 7
);
注: 外部キーに定義された CASCADE 削除はありません... Oracle では、SQL SERVER で実行できることを実行できません。
DELETE A
FROM A
INNER JOIN B on a.Id = b.id
WHERE b.Id = 2.....