原来的表数据结构:
我原本的想法是把father_phone这个字段名直接改成phone设置为非空 ,然后在把唯一性给删除。
我就通过下面的语句进行修改字段名
alter table students change father_phone phone varchar(11) not null;
结果为:
通过结果发现,字段的重命名和非空是已经设置好了,接下来就是删除唯一性了,我通过下面的代码删除:
alter table students drop index phone;
然后就出现错误:
解决方法:
show keys from students \G;
输出如下:
此时,就可以发现原来的father_phone改名为phone,虽然,名字和非空性已经改完成,但是这个unique属性的所有者还是father_phone便不是phone,所以会报错。
此时,只要输入下面的代码:
alter table students drop index father_phone;
看输出结果为:
此时,发现字段phone的unique已经删除。