mercoledì 9 marzo 2011

Erase the duplicates in a DB table (and "copy" tables!)

What if your table has got some duplicates (because you DO NOT define PRIMARY KEYS...)???

Well, we can select distinct rows from the table, and then create a new table with the resultset.
The syntax that we need is the following:

SELECT DISTINCT * INTO [new_table] FROM [old_table]
In addition, if the table already exist, we can use the INSERT INTO command:

INSERT INTO [new_table]
SELECT * FROM [old_table]

That's all!!! :)

Nessun commento: