1

多対多の関係にある 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.....
4

3 に答える 3

1

あなたが何をしたいのか理解できません。テーブル CustomerProduct からの削除は、次のような単純な削除ステートメントで実行できます。

  delete CustomerProduct 
  where ProductId = 1 and CustomerId  = 7
于 2013-01-18T02:22:12.097 に答える