Java servlets: duplicate key string in object with unique index "XAK1timItem"

I wrote this Java servlet that inserts elements into a table, but it fails. I think it might have something to do with my insert and delete, which is causing me problems. Java servlet runs insert statement in sql server. My error log says:

com.microsoft.sqlserver.jdbc.sqlserverexception: cannot insert duplicate key row in object 'dbo.timitem' with unique index 'XAK1timitem'. 

      

any ideas?

UPDATE: I found there is an index called "XAK1timItem (Unique, Non-Clustered)" which I'm not really sure what to do with .. hope this helps the question.

0


a source to share


1 answer


A unique index will ensure that the combination of rows included in the index is unique. Therefore, if you have a row in the database that has the same values ​​for the indexed column as the one you are trying to insert, you will get an error from the database.

The AK part indicates that it is a lternative k ey, which probably means that the table has a normal primary key and should not rely on AK to uniquely identify a row.



Some parameters:

  • drop the index if not needed
  • add another column to unique index
  • make the index non-unique so that it allows duplicate values
  • check if there is already a line that matches the one you are about to insert and abort the insert, but I guess you don't want to.
+1


a source







All Articles