mysql中设置某个表中的某个字段为…

来源:互联网 发布:iphone关闭数据流量 编辑:程序博客网 时间:2024/05/16 23:48

alter table tablename modify filedname int(11) auto_increment,add primary key (filedname);

tablename替换为表名,filedname替换为想要设置递增主键的字段名,11替换为数据长度。

 

删除主键(删除主键之前要确保主键不是自增长,即auto_increment的)
alter table service_code drop primary key;

若是主键为atuo_increment的需要先修改字段的属性:

alter table user modify column id int;在这里指定id的新类型为int,其他的如自增,自然是删掉了。

然后再添加主键
alter table service_code add primary key(id);
在添加主键之前,必须先把重复的id删除掉

 

 

 

0 0
原创粉丝点击