Mysql新增自增长主键列
2015-10-16 11:31
585 查看
有的时候需要对于一个Mysql数据库表添加个自动增长主键,刚开始的时候使用下面的语句:
alter table taskinfoconfig add column id int(10) not null auto_increment ;
alter table taskinfoconfig add primary key(id);
可是在执行的时候发现报错,信息如下:
Incorrect table definition; there are only one auto column and it must be defined as a key.
错误说明只有主键才能被指定为自动增长列,而上面的第一条语句在执行时id还不是主键,因此报错。
后来从网上找了找,其实可以使用一条语句解决:
alter table add taskinfoconfig add column id int(10) not null auto_increment primary key;
alter table taskinfoconfig add column id int(10) not null auto_increment ;
alter table taskinfoconfig add primary key(id);
可是在执行的时候发现报错,信息如下:
Incorrect table definition; there are only one auto column and it must be defined as a key.
错误说明只有主键才能被指定为自动增长列,而上面的第一条语句在执行时id还不是主键,因此报错。
后来从网上找了找,其实可以使用一条语句解决:
alter table add taskinfoconfig add column id int(10) not null auto_increment primary key;
相关文章推荐
- backup mysql for xtrabackup with xbstream and lz4
- mysql set赋值与select into 赋值的区别
- VBA连接MYSQL数据库(转载有修改)
- JDBC与MySql:手把手教你JDBC入门
- mysql 数据库分区
- servlet中访问mysql无法包含中文的解决
- mysql语句总结
- mysql远程访问
- mysql优化基础
- mysql使用
- 学习MySQL——下载与安装
- mysql sql中类似转换引起的索引无法使用的问题
- mysql性能优化建议
- mysqldump 的用法
- 17.3.1.1 Backing Up a Slave Using mysqldump
- Amoeba搞定mysql主从读写分离
- mysql windows 系统服务
- MySQL存储引擎--MyISAM与InnoDB区别
- MySQL proxy读写分离
- mysql5.6源码编译安装