在这里我想解释我的问题,
我需要在现有表中创建唯一索引,并且该表包含许多记录。
我试图执行此代码
CREATE UNIQUE INDEX empid_name ON employee (importcompany_id, employee_id, name, relationship);
但由于错误
#1062 - Duplicata du champ '0-Emp ID-Member Name-Relationship' pour la clef 'empid_name'
帮助我解决此问题,我需要使字段唯一
更新 :
设置这些字段唯一的原因是
其实我有这样的桌子
id company_ID Employee_ID Name Relationship Dob Age Gender
1 EMPL 00001 Choodamani Spouse 11-Aug-66 49 Female
2 EMPL 00001 Komala Mother 30-Oct-39 76 Female
3 EMPL 00001 Varshini Daughter 29-Apr-04 11 Female
4 EMPL 00001 Vasudevan Employee 15-Jul-62 53 Male
5 EMPL 00002 Siddharth Son 1-Jun-00 15 Male
6 EMPL 00002 Poongavanam Mother 21-Oct-39 76 Female
7 EMPL 00002 Aruna Spouse 16-Sep-68 47 Female
8 EMPL 00002 Abirami Daughter 7-May-97 18 Female
9 EMPL 00002 Murali Employee 7-Oct-67 48 Male
如果插入这样的数据,
id company_ID Employee_ID Name Relationship Dob Age Gender
1 EMPL 00001 Choodamani Spouse 11-Aug-70 45 Female
2 EMPL 00001 Nirmal Son 30-Oct-39 76 Female
此插入或更新是通过使用Excel工作表导入完成的
empid_name
列的员工表上具有唯一索引(importcompany_id, employee_id, name, relationship)
。然后,您必须删除现有的重复数据。简单的方法是在4列上添加UNIQUE索引。在编写ALTER语句时,请包含IGNORE
关键字。像这样:
ALTER IGNORE TABLE `employee` ADD UNIQUE INDEX(importcompany_id, employee_id, name, relationship);
这将删除所有重复的行。另外一个好处是,将来重复出现的INSERT将出错。与往常一样,您可能需要在运行类似操作之前进行备份。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句