gpt4 book ai didi

mysql - 如何在mysql中插入多表查询?

转载 作者:行者123 更新时间:2023-11-29 20:57:22 25 4
gpt4 key购买 nike

我有两个表:

客户:

enter image description here

员工:

enter image description here

如何在一个查询中插入多个表?

$sql="INSERT INTO saleorder ('employeeId','customerId','totalAmount','saleDate') values('$employeeId','$customerId','$totalAmount','$saleDate')";

$sql="INSERT INTO customer ('customerCode','customerName','gender','email') values('$customerCode','$customerName','$gender','$email')";

客户的_customerId是auto_increment,saleorder的saleorderId是auto_increment。

如果您能提供帮助,请解释一下语法。

最佳答案

在事务 block 中使用两个单独的插入查询,使您的操作原子化、更快、更安全(避免不一致)。

关于mysql - 如何在mysql中插入多表查询?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37521407/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com