Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Delete duplicate records
Message
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Divers
Thread ID:
00596573
Message ID:
00596691
Vues:
18
>I have a table from a client that never got a primary key put on the id field. There are 700 duplicate records where every field including id is duped. Is there any automatic way to rid these so that I can define a primary key on this id field? I know how to get a list of the dupes.
>
>Does adding an idx primary key field with seed 1 step 1 help?

Amendment: Sorry I did see this is SQL Server category. Never mind

First I would add a primary key field and valuate it for every record. Then the next 2 lines of SQL will do it:
SELECT * from TableX GROUP BY dupfield1, dupfield2, dupfield3 ;
   INTO CURSOR crsUnique
DELETE FROM TableX WHERE PKField NOT in (select PKField FROM crsUnique)
Just do not GROUP BY your PK Field.
Mark McCasland
Midlothian, TX USA
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform