August 7, 2007 at 1:38 pm
Ok, brand new to SQL and one of my new job descriptions is administering an application with SQL on the backend. I do not want anyone to instruct me on the use of SQL, I understand that much...I just need some guidance as to how to find the answer to my issue.
Help Please?
ITHubb
'People can only do to you what you allow them to.'
August 7, 2007 at 1:46 pm
For starters, use Books Online and this web site. Books Online is a great SQL Server resource and contains information on many common errors such as the duplicate key error you are getting. A search of SSC should also net results for your topic.
This is all I can really tell you without 'instructing' you
August 7, 2007 at 2:39 pm
Thanks for the deviation John, lol. I searched SSC and found only one thread pertaining to my issue but cannot help me because I did not manually insert the key, the program did. But I will take your advice on using the books online to see if I can come up with the solution.
And then again, maybe I need SOME instruction...
August 7, 2007 at 2:51 pm
The error itself is pretty straight forward. The application is attempting to insert a row and the key already exists. This leaves a couple of questions unanswered. What does the data represent? Should the row already exist? If not, why does it? If so, why is it attempting to insert a new one? Why doesn’t the application check for the existence of a row prior to attempting to insert one? Is this a one-time error or are you getting it often and if so, has the application code changed recently?
From a database perspective, SQL Server is doing its job here. The flaw is in code or logic. If you need to find out what the application is attempting to insert that is failing, I suggest running SQL Profiler and capturing the INSERT statement from the application. You can then search the table for the dupe and back-track yourself into the code and logic.
August 8, 2007 at 10:33 am
I appreciate the help John. Thanks much. I will get these questions answered and going forward, will know what questions to ask. I'm building a trace and will let you know the results of what I find.
Thanks again.
August 8, 2007 at 8:01 pm
Here's a powerful hint... the "key" this error message speaks to is either a "Primary Key" or a column with a UNIQUE index (usually a "Primary Key" for this error).
--Jeff Moden
Change is inevitable... Change for the better is not.
August 8, 2007 at 8:03 pm
Oh... almost forgot... if the code uses MAX(someid)+1 to determine the next "Key" or uses @@IDENTITY (SCOPE_IDENTITY is OK), that may be the source of the "Key" being out of sync with the data which would cause the attemp at the non-unique insertion to begin with.
--Jeff Moden
Change is inevitable... Change for the better is not.
August 9, 2007 at 9:16 am
My built-in human language pack does not compute. Can you explain that tom me in simpler terms? Lol
August 9, 2007 at 1:58 pm
Heh... yeah... Just look for anything that uses MAX(somecolumnname)+1 or @@IDENTITY in the code. If the aren't "in sync", it'll cause Primary Key violations which is the error you're getting.
Also, lookup @@Identity, Scope_Identity, Primary Key and Unique Index in Books Online to help with the human language pack thingy...
--Jeff Moden
Change is inevitable... Change for the better is not.
August 13, 2007 at 1:08 pm
So I've gone through the books online (Upgraded my language pack) and although very informative and enlightening, didn't resolve the issue for me. Being a Systems Admin, I took the route I knew best and uninstalled the app, deleted all registry entries and log files (Backed up of course) and re-installed the app. No more problems there. Only because it was specific to 2 users was this route taken. I'm still troubleshooting the actual error.
Viewing 10 posts - 1 through 10 (of 10 total)
You must be logged in to reply to this topic. Login to reply