sql - Query to delete duplicate records from a table created without primary key -
i want delete duplicate records without using row_number() function (sql server).
i see 2 options:
using
row_number()
, think best option unless your using sql server 2000 (which doesn't support it):delete yourtablerow (select *, row_number() on (partition yourid order yourid ) row yourtable) yourtablerow row!=1
the other option using
select distinct
put distinct rows table, delete rows in original table , insert again, this:select distinct * temptable yourtable truncate table yourtable -- faster delete yourtable insert yourtable select * temptable drop table temptable
if take approach recommend using regular table temptable instead of real
#temporaltable
because if connection dropped in middle of operation temporal table lose data.
Comments
Post a Comment