I have two tables:
TableY:
id, name, description
TableX:
id, name, y_id
I have added a foreign key in TableX (y_id REFERENCING tableY id ON DELETE CASCADE).
When I delete from TableX, the TableY id remains (while it theoritically should be deleted).
I guess I have misunderstood how the ON DELETE CASCADE option works. Can anyone tell what I am doing wrong?
I saw this ON DELETE CASCADE as well but did not make much sense to me.
I guess you got misunderstanding. Try to delete row from
TableYand corresponding rows fromTableXwill be cascade deleted. This option is indispensable when you have secondary related tables and would like to clean them all by deleting parent row from primary table without getting constraints violated or rubbish left.