Maha
Maha

Reputation: 23

I'm having a problem in deleting rows from several tables

I want to delete all the rows which have productid = 'value' from several tables so I tried to join between them but gives me an error

sql command not properly ended

so I was asking if this could actually work and if not can anyone tell me how should I do such a thing?

    DELETE FROM 
      products, products_admin, products_category, products_seller, categories
    USING 
      products 
    JOIN 
      products_admin ON products_admin.productid = products.productid 
    JOIN 
      products_category ON products_category.productid = products.productid 
    JOIN
      products_seller on products_seller.productid = products.productid
    JOIN 
      categories on categories.productsid = products.productid
    WHERE 
      products.productid = 'value';

here's what I tried

Upvotes: 1

Views: 52

Answers (1)

Vasya
Vasya

Reputation: 469

If you have foreign keys defined with ON DELETE CASCADE, deleting from products table will delete records from all associated tables. See https://www.techonthenet.com/oracle/foreign_keys/foreign_delete.php

Upvotes: 1

Related Questions