Can mysql set a joint unique index?

mysql can set the joint unique index, method: use the “Alter table table name add UNIQUE index index name (field 1, field 2)” statement to set, it will delete duplicate records, keep one, and then create Joint unique index. joint unique index The project needs to add a unique index to a certain two fields of a table , to ensure that the values ​​of these two fields cannot be duplicated at the same time. Alter table table name add UNIQUE index index name (field 1, field 2) When duplicate data already exists in the table , an error will be reported when adding, and the data needs to be deduplicated. 1. Check out the duplicate data first SELECT * FROM (SELECT field, COUNT(1 ) AS num FROM table GROUP BY field) temp WHERE num > Delete manually. 2.Alter ignore table table name add UNIQUE index index name (field 1, field 2) It will delete duplicate records (one will be kept ), and then create a unique index, which is efficient and user-friendly (not tested). I also found some related content: 1. Add PRIMARY KEY (primary key index) ALTER TABLE `table_name` ADD PRIMARY KEY ( `column` ) 2. Add UNIQUE…

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索