id INT NOT NULL PRIMARY KEY AUTO_INCREMENT然后删除数据库中的若干重复记录后ID变的不连续,如何变得连续??运行
ALTER TABLE tablename DROP id;
ALTER TABLE tablename ADD id INT NOT NULL PRIMARY KEY AUTO_INCREMENT FIRST后出错,求解!

解决方案 »

  1.   

    没有你所说的情况!mysql> create table t_spf19871001(id INT NOT NULL PRIMARY KEY AUTO_INCREMENT,col
    1 int);
    Query OK, 0 rows affected (0.08 sec)mysql> insert into  t_spf19871001(col1) values (10),(20),(30),(40),(50),(60),(70),(80),(90);
    Query OK, 9 rows affected (0.05 sec)
    Records: 9  Duplicates: 0  Warnings: 0mysql> select * from t_spf19871001;
    +----+------+
    | id | col1 |
    +----+------+
    |  1 |   10 |
    |  2 |   20 |
    |  3 |   30 |
    |  4 |   40 |
    |  5 |   50 |
    |  6 |   60 |
    |  7 |   70 |
    |  8 |   80 |
    |  9 |   90 |
    +----+------+
    9 rows in set (0.00 sec)mysql> delete from t_spf19871001 where id in (1,4,7,8);
    Query OK, 4 rows affected (0.05 sec)mysql> select * from t_spf19871001;
    +----+------+
    | id | col1 |
    +----+------+
    |  2 |   20 |
    |  3 |   30 |
    |  5 |   50 |
    |  6 |   60 |
    |  9 |   90 |
    +----+------+
    5 rows in set (0.00 sec)mysql> ALTER TABLE t_spf19871001 DROP id;
    Query OK, 5 rows affected (0.13 sec)
    Records: 5  Duplicates: 0  Warnings: 0mysql> ALTER TABLE t_spf19871001 ADD id INT NOT NULL PRIMARY KEY AUTO_INCREMENT
    FIRST;
    Query OK, 5 rows affected (0.13 sec)
    Records: 5  Duplicates: 0  Warnings: 0mysql> select * from t_spf19871001;
    +----+------+
    | id | col1 |
    +----+------+
    |  1 |   20 |
    |  2 |   30 |
    |  3 |   50 |
    |  4 |   60 |
    |  5 |   90 |
    +----+------+
    5 rows in set (0.00 sec)mysql>当您的问题得到解答后请及时结贴.
    http://topic.csdn.net/u/20090501/15/7548d251-aec2-4975-a9bf-ca09a5551ba5.html