插入mysql查询自动增量

时间:2014-04-08 16:56:40

标签: mysql phpmyadmin

我需要使用phpmyadmin

的查询插入新的增量值
INSERT INTO `ps_feature_shop`(`id_feature`, `id_shop`) VALUES ( '1', '1')

其中id_shop始终为1,而id_feature应该是增量的,具有我将决定的具体数字,例如1到1000或2000到30000。

我该怎么做?

2 个答案:

答案 0 :(得分:0)

如果您想在PHP代码中使用,这可能会对您有所帮助

<?php
    $startValue=1;
    $endValue=1000;
    function insertValue($startValue,$endValue){
         for($i=$startValue;$i<=$endValue;$i++){
            INSERT INTO `ps_feature_shop`(`id_feature`, `id_shop`) VALUES ( $i, '1');
         }
    }
    ?>

答案 1 :(得分:0)

您可以使用CREATE TABLE语句或稍后使用ALTER TABLE语句设置AUTO_INCREMENT列的起始值,请参阅https://dev.mysql.com/doc/refman/5.5/en/example-auto-increment.html

我从未使用它,但似乎您可以使用服务器选项auto_increment_increment全局指定增量。但该值将适用于服务器上的所有表。 见https://dev.mysql.com/doc/refman/5.5/en/replication-options-master.html#sysvar_auto_increment_increment

相关问题