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

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -