2016-05-30 85 views
0

我有兩個表:如何在mysql中插入一個多表的查詢?

客戶

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。

如果您可以提供幫助,請解釋語法。

回答

0

在事務性塊中使用兩個單獨的插入查詢來使您的oparation更加原子性,更快速和更安全(避免不一致)。