MySQL表添加自增列www.129028.com金沙

日期:2019-12-08编辑作者:数据库
mysql> create table zc_test2(id int);
Query OK, 0 rows affected (1.37 sec)

mysql> insert into zc_test2 values (10),(9),(8),(7),(6);
Query OK, 5 rows affected (0.04 sec)
Records: 5  Duplicates: 0  Warnings: 0

mysql> select * from zc_test2;
+------+
| id   |
+------+
|   10 |
|    9 |
|    8 |
|    7 |
|    6 |
+------+
5 rows in set (0.00 sec)

mysql> ALTER TABLE zc_test2 add id2 int;
Query OK, 0 rows affected (2.84 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql> select * from zc_test2;
+------+------+
| id   | id2  |
+------+------+
|   10 | NULL |
|    9 | NULL |
|    8 | NULL |
|    7 | NULL |
|    6 | NULL |
+------+------+
5 rows in set (0.00 sec)

mysql> alter table zc_test2 change id2 id2 int NOT NULL AUTO_INCREMENT;
ERROR 1075 (42000): Incorrect table definition; there can be only one auto column and it must be defined as a key

mysql> alter table zc_test2 change id2 id2 int NOT NULL AUTO_INCREMENT primary key;
Query OK, 5 rows affected (1.34 sec)
Records: 5  Duplicates: 0  Warnings: 0

mysql> select * from zc_test2;
+------+-----+
| id   | id2 |
+------+-----+
|   10 |   1 |
|    9 |   2 |
|    8 |   3 |
|    7 |   4 |
|    6 |   5 |
+------+-----+
5 rows in set (0.00 sec)

 

本文由www.129028.com金沙发布于数据库,转载请注明出处:MySQL表添加自增列www.129028.com金沙

关键词:

centos MySQL 5.5 源代码 cmake 安装

1.2 mysql安装方式介绍 1.rpm,yum:安装方便,安装速度快,无法定制(有依赖关系,安装依赖包) 2.二进制:不需要安装...

详细>>

mysql中列属性

非空约束 create table 表名( id int not null ); mysql列属性包括:NULL 、default、comment、primary key、unique key 唯一约束 create ta...

详细>>

MySQL 5.7基于GTID的主从复制www.129028.com金沙

  1 1.Check the necessary parameter is surely spedified. 2 (root@localhost mysql3306.sock)[(none)]04:04:00show variables like 'server_id'; 3 +--------...

详细>>

利用mysqlbinlog_flashback闪回丢失数据

        today,i'll have a test with the opensource tool mysqlbinlog_flashback which is released by 58daojia,here'sthe github address: https://githu...

详细>>