基于外键列的INSERT或UPDATE

时间:2016-06-02 14:45:44

标签: mysql

我的orderdetails表有orderdetailsID(PK),products_id(FK),customers_id(FK)和Quantity我想插入新订单如果products_id不存在则如果它确实存在那么更新数量这是否可能在mysql中?

$sql = "INSERT INTO orderdetails (products_id, Quantity, customers_id) VALUES($id,$stock,$customers_id) ON DUPLICATE KEY UPDATE    
Quantity = VALUES(Quantity);
";

0 个答案:

没有答案