Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"On Delete Cascade" if deleting a row from the child table

I'm having a difficult time understanding "on delete cascade" If I had the following example:

create table X (id int primary key, name char(10));

create table Y (bid int primary key, aid references A(id) on delete cascade);

X contains one row (111, 'Mike')

Y contains two rows (1000, 111), (2000, 111)**

I if removed row (2000,111) in table Y what would happen?

Would that row just be deleted or would it even allow me to delete anything because of the reference to the parent table?

Thanks

like image 959
William Roeser Avatar asked Dec 25 '22 20:12

William Roeser


1 Answers

It would be deleted and nothing else would happen. Cascading deletes only go from the referenced table to the referencing table. So a delete on table X will cascade a delete down to table y, while a delete on table y has no impact on table x.

like image 100
Declan_K Avatar answered Dec 28 '22 09:12

Declan_K