复制行及其所有“子级"

编程入门 行业动态 更新时间:2024-10-25 18:30:07
本文介绍了复制行及其所有“子级"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个名为employees的MySQL表.还有一个名为shifts的表,该表通过employeeId列与一对多关系绑定到employees.我想使用INSERT克隆一名员工及其班次-因此克隆了employee行,并且所有shifts都被克隆了,并具有为新的employee生成的新的自动递增主键.一个查询有可能吗?

I have a MySQL table called employees. There's another table called shifts that is tied to employees by the employeeId column and a one-to-many relationship. I want to clone an employee and his shifts using INSERT - so the employee row is cloned, and the shifts are all cloned and have the new auto-incrementing primary key that was generated for the new employee. Is this possible in one query?

推荐答案

是的,但不能一次插入.

Yes but not with a single insert.

您将需要一个INSERT来处理员工,然后再使用第二个INSERT来进行子选择,以选择所有班次数据.

You'd have one INSERT to do the employee, then a second INSERT with a sub-SELECT to SELECT all of the shift data.

以下是一些示例

更多推荐

复制行及其所有“子级"

本文发布于:2023-11-24 05:25:14,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1624108.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:quot

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!