0

I'm trying to delete 1 record based on primary key from (3) tables.

Here is the statement that I'm using

DELETE FROM CUSTOMER
WHERE EXISTS
  ( SELECT MERCHANTNAME
    FROM CREDITCARD
    WHERE MERCHANTNAME = 'VISA');

Deleting record of a customer with a VISA from customer table.

Here is the error that I'm getting

ORA-02292: integrity constraint (PLATINUMAUTOGROUP.CDRIVERLICENSENUM_FK) violated - child record found

I'm guessing CDRIVERLICENSENUM is the foreign key in the 3rd table that I have. How do I go about this? Is it possible to delete 1 record from 3 tables in 1 statement?

the three tables are

customer / customer_creditcard / creditcard
Riddick
  • 493
  • 1
  • 4
  • 7
  • Look into using `ON DELETE CASCADE`. If that would not work here (because of the direction of your delete), then you'll have to delete from the table mentioned in the error first. – Tim Biegeleisen Mar 08 '18 at 01:10

1 Answers1

0

You need to delete the records in the foreing tables before deleting the record in the primary table.

But perhaps your delete command in the CUSTOMER table might be wrong, because if the EXISTS command return true, all records will be deleted from the CUSTOMER table. Check if this is the result you expect.