mysql里面 如何通过SQL语句为某个已有字段添加自增属性
SQL code
mysql > alter table tt change id id int default null ; Query OK, 1 row affected ( 0.23 sec) Records: 1 Duplicates: 0 Warnings: 0 mysql > show create table tt; + -- -----+----------------------------------------------------------------------------------------------------------------------------------------------------------+ | Table | Create Table | + -- -----+----------------------------------------------------------------------------------------------------------------------------------------------------------+ | tt | CREATE TABLE `tt` ( `id` int ( 11 ) NOT NULL DEFAULT ' 0 ' , `Field1` varchar ( 255 ) DEFAULT NULL , PRIMARY KEY (`id`) ) ENGINE = InnoDB DEFAULT CHARSET = utf8 | + -- -----+----------------------------------------------------------------------------------------------------------------------------------------------------------+ 1 row in set ( 0.02 sec) mysql > alter table tt modify id int not null auto_increment; Query OK, 1 row affected ( 0.20 sec) Records: 1 Duplicates: 0 Warnings: 0 mysql > select * from tt; + -- --+--------+ | id | Field1 | + -- --+--------+ | 1 | 中国人 | + -- --+--------+