自动编号当达到最大值后再增加会怎么样,自动编号使用整形(mysql数据库)

解决方案 »

  1.   

    很简单,自己做个试验就知道了。mysql> create table jeff0002(id TINYINT primary key auto_increment,col1 int);
    Query OK, 0 rows affected (0.08 sec)mysql> select * from jeff0002;
    Empty set (0.00 sec)mysql> insert into jeff0002 values (125,125);
    Query OK, 1 row affected (0.05 sec)mysql> select * from jeff0002;
    +-----+------+
    | id  | col1 |
    +-----+------+
    | 125 |  125 |
    +-----+------+
    1 row in set (0.00 sec)mysql> insert into jeff0002(col1) values (126);
    Query OK, 1 row affected (0.05 sec)mysql> select * from jeff0002;
    +-----+------+
    | id  | col1 |
    +-----+------+
    | 125 |  125 |
    | 126 |  126 |
    +-----+------+
    2 rows in set (0.00 sec)mysql> insert into jeff0002(col1) values (127);
    Query OK, 1 row affected (0.03 sec)mysql> select * from jeff0002;
    +-----+------+
    | id  | col1 |
    +-----+------+
    | 125 |  125 |
    | 126 |  126 |
    | 127 |  127 |
    +-----+------+
    3 rows in set (0.00 sec)mysql> insert into jeff0002(col1) values (128);
    ERROR 1062 (23000): Duplicate entry '127' for key 'PRIMARY'
    mysql> select * from jeff0002;
    +-----+------+
    | id  | col1 |
    +-----+------+
    | 125 |  125 |
    | 126 |  126 |
    | 127 |  127 |
    +-----+------+
    3 rows in set (0.00 sec)mysql>
      

  2.   

    试验结果表明,会报 ERROR 1062 (23000): Duplicate entry '127' for key 'PRIMARY' 错误。
      

  3.   

    最好设大一点,int 10 。