MySQL on delete cascade, FK in source table

I have 2 tables, customer and address. Customer has column address with FK referencing to table address.

Table customer

create table customer
    id int(11) not null primary key,
    address    int(11) null,
    constraint fk_customer_address
        foreign key (address) references address (id)
        on update cascade on delete cascade,

Table address

create table address
id int(11) not null primary key,

I want to have address id in customer table, because in future there will be more tables referencing to address table (Users.address, Bussiness.address, etc) and one table for all addresses because of the same format.

When I delete row in customer table, address row stays in DB. Is it possible to use this FK relation to delete row in address table, or do I have to delete it manually (programmatically)?

Does this mean that when I delete row from address, customer row is deleted as well?

Yes, it does.

Read more here:

Content Attribution

This content was originally published by peter.cambal at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: