关于alter命令的使用
使用create table newtable select * from oldtable复制表时并没有复制主键、索引以及自增属性,要重新设定,即删除后再加上,且设为auto_increment的字段必须设为primary key
create table newtable select * from oldtable
alter table newtable drop id
alter table newtable add id int not null auto_increment,
alter table newtable add primary key(id);
使用create table newtable like oldtable可以复制所有的字段及其限制信息,包括主键自增,但其不能指定字段
两者都可以复制字段名、字段类型以及非空属性
alter命令在添加字段的值之前可以操作很多属性,如not null , auto_increment, 字段名,字段类型,default ,但是在添加字段值之后要考虑改变后存在冲突的情况,例如原本id字段非自增,如果设置为自增便会出错,原本default 为null,再设置为not null就会出错,要先设置为非null
使用modify或者change命令时只需要重新指定字段名称及类型以及非空属性即可,不必指定自增属性以及主键或者索引属性