'Error: can not delete or update parent row

I'm trying to Delete all the records related to this supplier from all relevant tables for Supplier with supplierNum = S3.

But when I try to delete, I get an error

Can not delete or update a parent row

I already ready few topics here about it but could not figure out a solution. can somebody please help me out?

CREATE TABLE supplier 
(
    supplierNum CHAR(2) NOT NULL,
    name CHAR(10) NOT NULL,
    status TINYINT(4) NOT NULL,
    city VARCHAR(10) NOT NULL,

    PRIMARY KEY (supplierNum)
);

CREATE TABLE parts 
(
    partNum CHAR(2) NOT NULL,
    name CHAR(10) NOT NULL,
    colour CHAR(8) NOT NULL,
    weight DECIMAL(3,1) NOT NULL,
    city VARCHAR(10) NOT NULL,

    PRIMARY KEY (partNum)
);

CREATE TABLE supplies 
(
    supplierNum CHAR(2) NOT NULL,
    partNum CHAR(2) NOT NULL,
    quantity SMALLINT(6) NOT NULL,

    PRIMARY KEY (supplierNum, partNum),
    FOREIGN KEY (supplierNum) 
            REFERENCES supplier (supplierNum),
    FOREIGN KEY (partNum) 
            REFERENCES parts (partNum)
);


Solution 1:[1]

If you need to delete all related rows from supplies while deleting the row from supplier table then you must add ON DELETE CASCADE option to the FOREIGN KEY definition.

If you want to remove unused rows from parts after above deletion (if such unused rows occures) them you must use trigger logic - such clearing cannot be performed with cascade action.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Akina