Home  >  Article  >  Backend Development  >  请问下多对多关联关系,中间表插入数据?还有设置中间表的好处

请问下多对多关联关系,中间表插入数据?还有设置中间表的好处

WBOY
WBOYOriginal
2016-06-06 20:33:171864browse

请问下多对多关联关系,中间表插入数据?
例如表user(id1,uname),role(id2,name),ueser_role(id1,di2,);
能不能实现在user表和role表插入数据后,ueser_role表自动插入数据呢?

回复内容:

请问下多对多关联关系,中间表插入数据?
例如表user(id1,uname),role(id2,name),ueser_role(id1,di2,);
能不能实现在user表和role表插入数据后,ueser_role表自动插入数据呢?

  • 可以考虑用Trigger
  • 但由于你的插入不一定会成功,要更好保证数据的一致性,应该用TRANSACTION
  • 如果只是一对一的关系,为什么不存一张宽表呢?比如表user:id/name/id2
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn