mysql - How should I structure my table and foreign keys? -
i noob when comes foreign keys please point me good/descriptive learning resources may helpful. let's trying build basic user/role system. have 2 tables:
user_role : id, role user: id, role_id, name
how , type of foreign key constraint should use in both tables? want role assigned 1 user cannot deleted till user moved role.
i using phpmyadmin, if can give directions it, appreciated.
a simple query adding foreign key constraint user table follows:
alter table `user` add constraint fk_user_role foreign key (`role_id`) references `user_role` (`id`)
that accomplish setting out do.
Comments
Post a Comment