[英]Mysql Query : auto-increment manipulation and update on the foreign table
My tables are : 我的桌子是:
orders(orderID,orderDesc)
orderscoding(orderscodingID,orderID,codeA)
I have around 230 records for both tables. 我两个表都有大约230条记录。
I want to alter the ( orderID
) auto-increment from 1,2,3,4,5 ..... to 100001,10002,10003,10004,10005 and reflect it on the related table , is this possible? 我想将( orderID
)自动增量从1,2,3,4,5 ....更改为100001,10002,10003,10004,10005并将其反映在相关表上,这可能吗?
So basically this will not work, as it is for new insert (but I want to modify existing records): 所以基本上这将不起作用,因为它适用于新插入(但我想修改现有记录):
ALTER TABLE orders AUTO_INCREMENT=100001;
If you want to update existing orderID
s, you can do like this 如果要更新现有的orderID
,可以这样做
UPDATE orders SET orderID = orderID + 10000
All existing orderID
will be incremented by 10000 with this query. 通过此查询,所有现有的orderID
将增加10000。 So, 1 will become 10001, 2 will be 10002 and so on... 因此,1将成为10001,2将成为10002,依此类推...
Do the same for orderscoding
table to keep it synced with orders
table (do the same if any more tables are synced to orderID
.) 对orderscoding
表执行相同orderscoding
以使其与orders
表保持同步(如果还有更多表同步至orderID
则执行相同orderID
。)
UPDATE orderscoding SET orderID = orderID + 10000
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.