dbthingsensureIndex({“name”:1},{unique:true})这是由于将要被设置为主键的字段下已经存在记录值并且这些字段值还存在有重复,无法满足主键字段必须是唯一的要求,因此报错、设置失败。
解决办法是先删除该字段下那些有重复的字段值,然后才设置该字段为主键。普通索引\x0d\这是最基本的索引类型,而且它没有唯一性之类的限制。\x0d\唯一性索引\x0d\这种索引和前面的“普通索引”基本相同,但有一个区别:索引列的所有值都只能出现一次,即必须唯一。1、查找表中多余的重复记录,重复记录是根据单个字段(peopleId)来判断
select from peoplewhere peopleId in (select peopleId from people group by peopleId having count (peopleId) > 1)
2、删除表中多余的重复记录,重复记录是根据单个字段(peopleId)来判断,只留有rowid最小的记录
delete from people where peopleId in (select peopleId from people group by peopleId having count (peopleId) > 1)and rowid not in (select min(rowid) from people group by peopleId having count(peopleId )>1)
3、查找表中多余的重复记录(多个字段)
select from vitae awhere (apeopleId,aseq) in (select peopleId,seq from vitae group by peopleId,seq having
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)