外键链接

时间:2017-02-16 22:54:15

标签: mysql database foreign-keys multiple-tables cascading-deletes

我可以拥有这样的模型:

create table address (address_id int primary key, .....);
create table event (event_id int primary key,.....);
create table event_addresses (
     event_id int foreign key references event(event_id), 
     address_id int foreign key references address(address_id),
     primary key (event_id, address_id)
); 
create table user_events(
     user_id int foreign key references users(user_id),
     event_id int foreign key references event_addresses(event_id) on delete cascade,
     primary key (user_id, event_id)
);

这样无论何时更改事件地址,都可以删除event_addresses中的条目,并将其级联到user_events。以这种方式链接外键是一种好习惯吗?

0 个答案:

没有答案