表已经在Mysql中建好了,而且我现在不能更改表。  
现在导入数据需要ID字段自动添加,以前在建表的时候ID并不是设成自动增长的。
求高手!!!

解决方案 »

  1.   

    在MS-SQL中设置成自增列就好了 在MYSQL中不清楚
      

  2.   

    insert ta
    select ID=row_number()over(order by getdate()),
           *
    from tb
      

  3.   

    alter table test drop column id
    alter table test add id int IDENTITY (1,1)
      

  4.   

    insert into tb select id=identity(int,1,1) ,* from tb
      

  5.   

    不知道MSQL是什么东西,SQL中是IDENTITY
      

  6.   

    mysql> show create table t2\G
    *************************** 1. row ***************************
           Table: t2
    Create Table: CREATE TABLE `t2` (
      `id` int(11) DEFAULT NULL,
      `total` int(11) DEFAULT NULL
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8
    1 row in set (0.03 sec)mysql> alter table t2 modify id int auto_increment primary key;
    Query OK, 0 rows affected (0.17 sec)
    Records: 0  Duplicates: 0  Warnings: 0mysql> show create table t2\G
    *************************** 1. row ***************************
           Table: t2
    Create Table: CREATE TABLE `t2` (
      `id` int(11) NOT NULL AUTO_INCREMENT,
      `total` int(11) DEFAULT NULL,
      PRIMARY KEY (`id`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8
    1 row in set (0.00 sec)mysql>