mysql ID有重复值后设置主键的实例代码
发布时间:2016-01-24 编辑:jiaochengji.com
在mysql数据库中,字段ID中已存在重复值,在这种情况下如何设置主键呢?本文分享一例实现代码,供有需要的朋友作个参考。
本节内容:
mysql中字段ID有重复值,然后设置主键的方法。
例句:
复制代码 代码示例:
//--在mysql重复值存在的情况下设置主键
select @t:=0;
update tbl_order set a=(@t:=@t+1);
alter table tbl_order add primary key(id);
alter table tbl_order change id id int(11) not null auto_increment;
select @t:=0;
update tbl_order set a=(@t:=@t+1);
alter table tbl_order add primary key(id);
alter table tbl_order change id id int(11) not null auto_increment;
您可能感兴趣的文章:
mysql字段、主键、索引等的创建与修改命令
Mysql复制主键冲突的问题及解决方法
了解 MySQL 主键与索引的联系与区别
您可能感兴趣的文章:
mysql ID有重复值后设置主键的实例代码
Mysql设置自增长主键的起始值
MySQL自增字段的设置方法分享
Mysql 自增字段设定基值的sql语句
深入解析mysql自增字段auto_commit
Mysql 主键自增长auto_increment问题分析
mysql字段、主键、索引等的创建与修改命令
centos源码安装mysql-5.1.53的实例详解
mysql设置当前时间为默认值的方法举例
Linux下指定数据库数据配置主主同步的实例
[关闭]