使用多对多关系插入 [英] insert using many to many relationship

查看:91
本文介绍了使用多对多关系插入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们可以使用SQL的insert命令在具有多对多关系的表中插入数据吗?可以通过明智的查询来完成,也可以通过一个查询来完成.因为有三个表.

Can we use insert command of SQL for inserting the data in tables having many to many relationships. Can it be done by saparate queries or we done it with the one query. as there are three tables.

推荐答案

只有一个插入.您获取用户的ID和角色的ID.但是,我会在做两件事的存储过程中做到这一点.首先是,检查该对值是否已在表中.如果是这样,请勿尝试再次插入.如果不是,则将其插入.
There''s only one insert. You take the id of the user and the id of the role. But, I''d do it in a stored proc that does two things. The first is, check if that pair of values is in the table already. If it is, don''t try to insert it again. If it''s not, then insert it.


这篇关于使用多对多关系插入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆