è¤æ°ã«ã©ã ã§ã¦ãã¼ã¯ãã¼ãä½ãããã¨ããéè¤ãããã¨ã¨ã©ã¼ã«ãªã
mysql> ALTER TABLE hoge ADD UNIQUE (a,b,c); ERROR 1062 (23000): Duplicate entry 'aiueokakikukekoaaaaa' for key 2
IGNOREãã¤ããã¨ãéè¤ããã«ã©ã ã¯æåã®åã ãæ¡ç¨ããã¦æ£å¸¸çµäºãã
mysql> ALTER IGNORE TABLE hoge ADD UNIQUE (a,b,c); Query OK, 225165 rows affected (52.52 sec) Records: 225165 Duplicates: 1385 Warnings: 0
ã²ã¨ã¤ã®ã«ã©ã ã«ã¦ãã¼ã¯ãã¼ãä½ãããã ããªããéè¤ã¬ã³ã¼ããåé¤ãã¦ãã¾ãã°å¤§ä½åé¡ãªã
DELETE FROM hoge WHERE a in (SELECT a FROM hoge GROUP BY a HAVING COUNT(*)>1);
è¤æ°ã«ã©ã ã®ã¨ãã¯ã©ãããã¯ã¨ãªã¼ããããããããªãã£ãã®ã§ããã¼ãã«ãä½ãç´ãæ¹æ³ãæ¡ç¨ãã
CREATE TABLE piyo LIKE hoge; ALTER TABLE piyo ADD UNIQUE (a,b,c); INSERT IGNORE INTO piyo SELECT * FROM hoge; DROP TABLE hoge; ALTER TABLE piyo RENAME TO hoge;
ããããALTER TABLEã«IGNOREã使ãããã¨ãå¤æããã®ã§ããã