开发者

Foreign Keys, question on relations

开发者 https://www.devze.com 2022-12-17 21:36 出处:网络
I\'ve been toying with MySQL today and reading their documentation, gotten some handy information of optimization and a lot of things I didn\'t know. Now I\'ve been adding foreign keys to my web appli

I've been toying with MySQL today and reading their documentation, gotten some handy information of optimization and a lot of things I didn't know. Now I've been adding foreign keys to my web application because it add constrains and I see it quite helpful.

My doubt is, right now there is a Roles table and a Users table, I set a relation on user's RoleID that when the role ID is removed (from the Roles table, parent) it should the user is deleted.

Now I kinda have the answer but I prefer someone to confirm, the ID has to match? or does the fo开发者_Go百科reign key takes action regardless if it matches or not?


The foreign key constraints will only take place where the ID is matched. In other words, it won't remove users of different RoleIDs, only those users which have the RoleID of the deleted Role.

0

精彩评论

暂无评论...
验证码 换一张
取 消