sql server 2008 - SQL Script for Bulk Deletion -


i attempting write sql script bulk delete rows in table input text file. getting sql scripting.

backstory: in previous role setup table without primary key , program designed insert data table. however, program never check duplicate entries first , go ahead , insert.

i attempting clean-up database.

first, have run query see how many rows duplicates. there ~7,000 therefore, there no way going delete them 1 query @ time. [id] should have been setup primary key.

query determine duplicates

select [id] [testing].[dbo].[testingtable] group [id] having count(*) > 1 

i can delete duplicate rows using following query on individual id:

set rowcount 1 delete [testing].[dbo].[testingtable] [id] = somenumber set rowcount 0 

i have text file of of duplicate id number entries, however, there bulk delete script can create can feed in of id duplicate numbers text file? or there more efficient way. please point me in direction.

i don't understand why have (or need) text file of duplicate ids.

there ~7,000 therefore, there no way going delete them 1 query @ time
of course there way delete them, here go:

if want remove duplicates table, use code:

with cte as(    select [id]          ,rn = row_number()over(partition [id])    [testing].[dbo].[testingtable] ) delete cte rn > 1    

Comments

Popular posts from this blog

neo4j - finding mutual friends in a cypher statement starting with three or more persons -

php - How to remove letter in front of the word laravel -

minify - Minimizing css files -