有个表a,主键id,我想创建个临时表从表a中拿数据,并重新设置自增长的主键uids。

解决方案 »

  1.   

    详细说明,
    并重新设置自增长的主键uids:A表?
      

  2.   

    IDENTITY (1,1) PRIMARY KEY)
      

  3.   

    create temporary table aa(uids int primary key auto_increment,num text)
    select num from a;
    把表a的num字段给临时表aa的num字段这样?
      

  4.   

    num 是我自己一个测试的字段,你把你自己表上的字段放上去撒.
      

  5.   

    create table cmp as select f1,f2 from a;
    ALTER TABLE cmp ADD id INT AUTO_INCREMENT PRIMARY KEY
      

  6.   

    create table a(id int auto_increment primary key,f int);
    insert into a values (1,1),(2,2),(3,3);create table temp_a as select * from a;
    mysql> desc a;
    +-------+---------+------+-----+---------+----------------+
    | Field | Type    | Null | Key | Default | Extra          |
    +-------+---------+------+-----+---------+----------------+
    | id    | int(11) | NO   | PRI | NULL    | auto_increment |
    | f     | int(11) | YES  |     | NULL    |                |
    +-------+---------+------+-----+---------+----------------+
    2 rows in set (0.01 sec)mysql> select * from a;
    +----+------+
    | id | f    |
    +----+------+
    |  1 |    1 |
    |  2 |    2 |
    |  3 |    3 |
    +----+------+
    3 rows in set (0.00 sec)mysql> alter table temp_a add uids int auto_increment primary key;
    Query OK, 3 rows affected (0.09 sec)
    Records: 3  Duplicates: 0  Warnings: 0mysql> desc temp_a;
    +-------+---------+------+-----+---------+----------------+
    | Field | Type    | Null | Key | Default | Extra          |
    +-------+---------+------+-----+---------+----------------+
    | id    | int(11) | NO   |     | 0       |                |
    | f     | int(11) | YES  |     | NULL    |                |
    | uids  | int(11) | NO   | PRI | NULL    | auto_increment |
    +-------+---------+------+-----+---------+----------------+
    3 rows in set (0.02 sec)mysql> select * from temp_a;
    +----+------+------+
    | id | f    | uids |
    +----+------+------+
    |  1 |    1 |    1 |
    |  2 |    2 |    2 |
    |  3 |    3 |    3 |
    +----+------+------+
    3 rows in set (0.00 sec)mysql>