943,983 Members | Top Members by Rank

Ad:
  • MS SQL Discussion Thread
  • Marked Solved
  • Views: 49095
  • MS SQL RSS
You are currently viewing page 2 of this multi-page discussion thread; Jump to the first page
Mar 6th, 2008
0

Re: how to delete duplicate record in a table by using SQL query

Well guys.. im new for MS SQL.. i have a solution & it worked perfectly with me.

while creating table just add an extra attribute using identity keyword:
MS SQL Syntax (Toggle Plain Text)
  1. attributename int identity(1,1)
so everytime you insert any row, it will increase 1. so there will a unique number for every row

Regards!
Last edited by puneetkay; Mar 6th, 2008 at 7:36 am.
Reputation Points: 51
Solved Threads: 24
Junior Poster
puneetkay is offline Offline
122 posts
since Nov 2007
Mar 6th, 2008
0

Re: how to delete duplicate record in a table by using SQL query

mssql Syntax (Toggle Plain Text)
  1. DELETE FROM emp e WHERE rowid>(SELECT MIN(ROWID) FROM emp WHERE e.empno=empno)
Reputation Points: 1182
Solved Threads: 392
Posting Sensei
Jx_Man is offline Offline
3,145 posts
since Nov 2007
Mar 7th, 2008
0

Re: how to delete duplicate record in a table by using SQL query

Just solve the thing with a cursor

like
declare del_dups cursor
for
select * from <table_name>
group by column_name
having count(*) > 1

(column_name where the duplicates are)

open del_dups

fetch next from del_dups into ......

while @@fetch_status <> 0
begin
delete from table_name where current of cursor
fetch next from del_dups into ....
end

close del_dups
deallocate del_dups

For the update you should change te delete statement to

update table_name set ... = .... where current of cursor
Reputation Points: 10
Solved Threads: 1
Newbie Poster
space1000 is offline Offline
9 posts
since Mar 2008
Oct 30th, 2009
0
Re: how to delete duplicate record in a table by using SQL query
hey im workin out smthin hre will get back to u. i seem to be havin an idea
Reputation Points: 10
Solved Threads: 0
Newbie Poster
edgarkuhimbisa is offline Offline
1 posts
since Oct 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in MS SQL Forum Timeline: MS SQL: Converting row printing to column based printing
Next Thread in MS SQL Forum Timeline: syntax query for backup database for one month in sql server 2000





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC