MySQL SQL Delete Notes MySQL SQL supprimer des notes
To delete duplicates from a MySQL database table I normally copy the duplicate data first to a temporary table and then use the copied id’s to delete from the original table. Pour supprimer les doublons d'une table de base de données MySQL normalement je copie la duplication des données tout d'abord à une table temporaire, puis utiliser la copie de l'identifiant de supprimer de la table d'origine.
Delete using the temporary can take two forms. Supprimer l'aide temporaire peut prendre deux formes. First is the slow way: Tout d'abord, la lenteur façon:
delete from target where id in (select id from temp); objectif de supprimer WHERE id IN (SELECT id de temp);
This can be agonizingly slow for a large table. Cela peut être désespérément lente pour une grande table. A much faster option is: Une option beaucoup plus rapide est la suivante:
delete target from target, temp where target.id = temp.id; supprimer cible de cible, où target.id temp = temp.id;
BTW: The copying into temporary table part is simple but not that simple. TVA: La copie en partie table temporaire est simple mais pas si simple. Here’s what I do: Voici ce que je fais:
insert into temp(id) select b.id from target a, target b where a.common_field1 = b.common_field1 and a.common_field2 = b.common_field2 … and a.id < b.id ; insert into temp (id) b.id de sélectionner une cible, la cible a.common_field1 où b = b.common_field1 et a.common_field2 = b.common_field2… et a.id <b.id;
Note: I am assuming all the tables have an unique row identifier (primary key). Note: Je suis en supposant que toutes les tables ont une ligne unique d'identification (clé primaire).
Filed under Classé sous Database Base de données , Headline News Headline News , How To Comment , MySQL , Open Source Software Open Source Software , RDBMS SGBDR | |
| |
RSS 2.0 RSS 2,0 | |
Trackback this Article | cet article |
Email this Article Envoyer cet article
You may also like to read Vous mai également à lire |



