Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Does MS SQL Server store an Internal ID for each row

Posted on 2004-04-19
12
1,086 Views
Last Modified: 2008-02-01
We have a table in which a backup was imported twice and as a result each row is there twice. So there is no way to uniquely identify each row because they duplicates have identical everything including the IDENTITY field

Does MS SQL Server make a value available that tells us which row is more recent, some internal row ID?

0
Comment
Question by:moonrise
  • 5
  • 3
  • 3
  • +1
12 Comments
 
LVL 34

Expert Comment

by:arbert
ID: 10865108
Nope.  Do you just want to delete a duplicate?
0
 
LVL 34

Expert Comment

by:arbert
ID: 10865128
Is the recovery mode on your database set to full?  If so, you could also backup the log and then do a point in time restore before the import was done the second time.
0
 

Author Comment

by:moonrise
ID: 10865184
Yes, I just want to delete duplicates, but duplicates are identical

We cannot restore because more live data is being created every second
0
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 
LVL 34

Expert Comment

by:arbert
ID: 10865231
acperkins had a good solution on this post--it's actually much easier since you have an identity on the table:

http://www.experts-exchange.com/Databases/Microsoft_SQL_Server/Q_20381662.html


you might want to consider adding a unique index or primary key to avoid this in the future.

Brett
0
 

Author Comment

by:moonrise
ID: 10865523
The solution mentionned assumes that the duplicates have different values for at least one field, in that case record_id. In my situation we don't have any field different.
0
 
LVL 34

Expert Comment

by:arbert
ID: 10865539
Yes, didn't you say there was an identity field on each record?  That's your different value....
0
 
LVL 34

Expert Comment

by:arbert
ID: 10865549
Ahhhh, unless you used SET IDENTITY_INSERT and inserted duplicate Idents?
0
 
LVL 4

Expert Comment

by:kssaran
ID: 10866326
Hi Moonrise,

Try something using property called ROWGUIDCOL(Globally Unique Identifiers)  & see if you can get some result of what u wanted

Rgds
Sara
0
 
LVL 13

Accepted Solution

by:
danblake earned 250 total points
ID: 10866631
Moonrise,

You're going to need a seperate table, like this:
http://support.microsoft.com/default.aspx?scid=kb;en-us;70956

Or alternativly create the second seperate table and a covering index (with ignore dups option on) then populate the table with your rows and truncate the original table, copying from the second table to the first.
http://www.experts-exchange.com/Databases/Microsoft_SQL_Server/Q_20956727.html
(There's a reason why this question is still open..)
(This is a better way of achieving what you want than the KB article from MS)

This should remove the dups quickly.

Rgds,

Dan.
0
 
LVL 13

Expert Comment

by:danblake
ID: 10866646
or not even a truncate -- you could run a delete where rows exist in the second table only, and then enable an indentity insert on again to ensure you can still populate to your live table... But it does depend on how many rows we are dealing with here as to the best mechanism for attack....

Alternativly you can write a procedure to trap the error code returned from ignore dups, and delete the highest occuring duplicate (with a copy in a second table) from the first then populate this record back into the original table.

There are many ways of deleting these dups.
0
 

Author Comment

by:moonrise
ID: 10869581
thank you
0
 
LVL 13

Expert Comment

by:danblake
ID: 10869758
No worries moonrise, glad to help.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question