[英]Insert new record into a table with composite primary key
This question may be very simple but I have been struggling to find a solution. 这个问题可能很简单,但我一直在努力寻找解决方案。 Here is what I have, table order with two composite primary key (order_id, order_detail_id).
这里是我有什么,有两个复合主键(ORDER_ID,order_detail_id)表顺序。 This is just for an illustration purpose but my prd table is of the same concept.
这只是出于说明的目的,但是我的prd表具有相同的概念。
Order 订购
order_id | order_detail_id | order_name
My question is how to insert a new record with an existing order_id. 我的问题是如何使用现有的order_id插入新记录。 Let's say these are the rows existing,
假设这些是现有的行,
1 | 1 | 'Order 1 Detail 1'
1 | 2 | 'Order 1 Detail 2'
2 | 1 | 'Order 2 Detail 1'
Now I want to a new order detail into the existing order 1. I use Mysql 5 with InnoDB. 现在,我想将新订单详细信息添加到现有订单1中。我将Mysql 5与InnoDB一起使用。 Any help is appreciated.
任何帮助表示赞赏。
insert into order
select order_id, max(order_detail_id) + 1, 'Order 1 Detail 3'
where order_id=1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.