Delete a child and a parent row with one SQL script

After some really bad experiences with this problem on a relatively big and extremely critical database, I decided to make a Silver bullet for it! because I couldn't find any! Actually, none of the solutions/answers in this thread meet the problem's needs.

See CASCADELETE repo on my github.


Define your foreign keys with cascading deletes. Then you only need to delete the "parent" row.


delete from 
(
select * from parent join child using (id)
where id = 1
)

WARNING! Will only delete where both parent AND child rows exist. Will NOT delete parents without children