如何为MySQL中的特定表自动增加2 [英] How to auto increment by 2 for a particular table in mysql

查看:92
本文介绍了如何为MySQL中的特定表自动增加2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2个表order_retailer和order_customer

I have 2 tables order_retailer and order_customer

它们都具有自动递增的主键order_id

they both have auto incremented primary key order_id

要在整个系统中保持唯一的订单ID,我希望order_retailer仅将ID作为偶数编号,对于order_customer,这些ID将为奇数.为此,我必须将autoincrement的增量值设置为2.是否可以在mysql中以表格方式设置它.

To keep an order id unique in the whole system I want order_retailer to have id as even numbers only and for order_customer the ids will be odd. For this I have to set the autoincrement's increment value to 2. is it possible to set it table wise in mysql.

我不想要php解决方案.请让我知道是否有一个命令/查询来将垂直表的自动增量移位设置为2. 另外我也不想更改服务器变量auto_increment_increment或auto_increment_offset或任何其他服务器变量

I don't want a php solution. please let me know if there is a command/query to set the auto increment shift to 2 for a perticular table. Also I don't want to change the server variables auto_increment_increment or auto_increment_offset or any other server variable

推荐答案

否,无法在表格上进行设置.

No it is not possible to set it table wise.

Mysql具有2个变量auto_increment_incrementauto_increment_offset,并且默认情况下,这两个变量的值均为1.如果您更改任何值,将具有全局作用.

Mysql has 2 variable auto_increment_increment and auto_increment_offset and values of both these variables are 1 by default. If you change any of the value it will have global effect.

要解决您的问题,请创建一个存储过程,该存储过程将根据需要具有偶数id的需求来实现.

To solve your problem create a stored procedure which will according to needs of having even id.

引用此链接 http://dev .mysql.com/doc/refman/5.0/en/replication-options-master.html#sysvar_auto_increment_increment

希望这会有所帮助

这篇关于如何为MySQL中的特定表自动增加2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆