dbTalk Databases Forums  

SQL Duplicate Error

comp.databases.ms-sqlserver comp.databases.ms-sqlserver


Discuss SQL Duplicate Error in the comp.databases.ms-sqlserver forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
SJ
 
Posts: n/a

Default SQL Duplicate Error - 06-20-2007 , 11:51 AM






Hi!

I am trying to do a simple udpate on a table and I am getting the
error:

"Cannot insert duplicate key row in object 'UserInfo' with unique
index 'UserInfo_Login'.The statement has been terminated."

Here is the command I am trying to run
---
USE Deve2_SITE

update UserInfo set tp_Login=N'DEV2\sam', tp_Email=N'test (AT) test (DOT) com',
tp_Title=N'Samson, Sammy'
WHERE (tp_Login=N'DEV\sam')
--

Any ideas?


Reply With Quote
  #2  
Old   
Roy Harvey
 
Posts: n/a

Default Re: SQL Duplicate Error - 06-20-2007 , 12:02 PM






What it seems to be saying is that there is already a row in the table
with the value N'DEV2\sam', and the index UserInfo_Login has a unique
constraint that does not permit duplicates. However it is possible
the index has multiple columns. To know exactly you would need to
know the details of the definition of the index UserInfo_Login on the
table UserInfo. You could find that out by running:

EXEC sp_helpindex Deve2_SITE..UserInfo

Roy Harvey
Beacon Falls, CT

On Wed, 20 Jun 2007 09:51:15 -0700, SJ <sjourdan (AT) gmail (DOT) com> wrote:

Quote:
Hi!

I am trying to do a simple udpate on a table and I am getting the
error:

"Cannot insert duplicate key row in object 'UserInfo' with unique
index 'UserInfo_Login'.The statement has been terminated."

Here is the command I am trying to run
---
USE Deve2_SITE

update UserInfo set tp_Login=N'DEV2\sam', tp_Email=N'test (AT) test (DOT) com',
tp_Title=N'Samson, Sammy'
WHERE (tp_Login=N'DEV\sam')

Reply With Quote
  #3  
Old   
Alex Kuznetsov
 
Posts: n/a

Default Re: SQL Duplicate Error - 06-20-2007 , 01:42 PM



On Jun 20, 11:51 am, SJ <sjour... (AT) gmail (DOT) com> wrote:
Quote:
Hi!

I am trying to do a simple udpate on a table and I am getting the
error:

"Cannot insert duplicate key row in object 'UserInfo' with unique
index 'UserInfo_Login'.The statement has been terminated."

Here is the command I am trying to run
---
USE Deve2_SITE

update UserInfo set tp_Login=N'DEV2\sam', tp_Email=N't... (AT) test (DOT) com',
tp_Title=N'Samson, Sammy'
WHERE (tp_Login=N'DEV\sam')
--

Any ideas?
In addition to Roy's advice, do you have triggers on your table?

http://sqlserver-tips.blogspot.com/



Reply With Quote
  #4  
Old   
SJ
 
Posts: n/a

Default Re: SQL Duplicate Error - 06-20-2007 , 01:55 PM



On Jun 20, 1:42 pm, Alex Kuznetsov <AK_TIREDOFS... (AT) hotmail (DOT) COM> wrote:
Quote:
On Jun 20, 11:51 am, SJ <sjour... (AT) gmail (DOT) com> wrote:





Hi!

I am trying to do a simple udpate on a table and I am getting the
error:

"Cannot insert duplicate key row in object 'UserInfo' with unique
index 'UserInfo_Login'.The statement has been terminated."

Here is the command I am trying to run
---
USE Deve2_SITE

update UserInfo set tp_Login=N'DEV2\sam', tp_Email=N't... (AT) test (DOT) com',
tp_Title=N'Samson, Sammy'
WHERE (tp_Login=N'DEV\sam')
--

Any ideas?

In addition to Roy's advice, do you have triggers on your table?

http://sqlserver-tips.blogspot.com/- Hide quoted text -

- Show quoted text -
Thanks all. I guess i dont know what an index is. And why an update
would matter. This is the result of the EXEC command:

UserInfo_FullText nonclustered, unique located on PRIMARY tp_GUID
UserInfo_Login nonclustered, unique located on PRIMARY tp_SiteID,
tp_Login, tp_Deleted
UserInfo_PK clustered, unique, primary key located on PRIMARY
tp_SiteID, tp_ID
UserInfo_SID nonclustered, unique located on PRIMARY tp_SiteID,
tp_SystemID

ANy ideas? Why is an update command doing an insert (that is probably
a dumb question)



Reply With Quote
  #5  
Old   
Roy Harvey
 
Posts: n/a

Default Re: SQL Duplicate Error - 06-20-2007 , 02:27 PM



Quote:
UserInfo_Login nonclustered, unique located on PRIMARY tp_SiteID,
tp_Login, tp_Deleted
OK, the UNIQUE contraint is on three columns, the combination of
tp_SiteID, tp_Login and tp_Deleted.

The UPDATE command is not doing an INSERT, but it is changing the
value of the column so that the combination of those three columns
conflicts with data already in the table - it woud violate the UNIQUE
contraint.

If you run the query:

SELECT *
FROM Deve2_SITE..UserInfo
WHERE tp_Login IN ( N'DEV\sam', N'DEV2\sam')
ORDER BY tp_Login, tp_SiteID, tp_Deleted

That will show the rows that are in conflict. What you are looking
for is that there is already DEV2\sam for at least one matching pair
of tp_SiteID/tp_Deleted values.

Hope that helps.

Roy Harvey
Beacon Falls, CT

On Wed, 20 Jun 2007 11:55:41 -0700, SJ <sjourdan (AT) gmail (DOT) com> wrote:

Quote:
On Jun 20, 1:42 pm, Alex Kuznetsov <AK_TIREDOFS... (AT) hotmail (DOT) COM> wrote:
On Jun 20, 11:51 am, SJ <sjour... (AT) gmail (DOT) com> wrote:

Hi!

I am trying to do a simple udpate on a table and I am getting the
error:

"Cannot insert duplicate key row in object 'UserInfo' with unique
index 'UserInfo_Login'.The statement has been terminated."

Here is the command I am trying to run
---
USE Deve2_SITE

update UserInfo set tp_Login=N'DEV2\sam', tp_Email=N't... (AT) test (DOT) com',
tp_Title=N'Samson, Sammy'
WHERE (tp_Login=N'DEV\sam')
--

Any ideas?

In addition to Roy's advice, do you have triggers on your table?

http://sqlserver-tips.blogspot.com/- Hide quoted text -

- Show quoted text -

Thanks all. I guess i dont know what an index is. And why an update
would matter. This is the result of the EXEC command:

UserInfo_FullText nonclustered, unique located on PRIMARY tp_GUID
UserInfo_Login nonclustered, unique located on PRIMARY tp_SiteID,
tp_Login, tp_Deleted
UserInfo_PK clustered, unique, primary key located on PRIMARY
tp_SiteID, tp_ID
UserInfo_SID nonclustered, unique located on PRIMARY tp_SiteID,
tp_SystemID

ANy ideas? Why is an update command doing an insert (that is probably
a dumb question)

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.