Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


cannot insert duplicate key row in object 'tablename' with unique index 'indexname'


cannot insert duplicate key row in object 'tablename' with unique index 'indexname'

Author
Message
VRT
VRT
SSC-Enthusiastic
SSC-Enthusiastic (186 reputation)SSC-Enthusiastic (186 reputation)SSC-Enthusiastic (186 reputation)SSC-Enthusiastic (186 reputation)SSC-Enthusiastic (186 reputation)SSC-Enthusiastic (186 reputation)SSC-Enthusiastic (186 reputation)SSC-Enthusiastic (186 reputation)

Group: General Forum Members
Points: 186 Visits: 603
Hi,

I have an MS Access application whose tables are linked via ODBC connection to SQL server 2005. In one of the form when user is trying to change the data it is giving the below error

ODBC--call failed

[Micorsoft][ODBC SQL Server Driver][SQL Server]cannot insert duplicate key row in object 'tablename' with unique index 'indexname'. (#2601)
[Micorsoft][ODBC SQL Server Driver][SQL Server]The statement has been terminated. (#3621)



But when check the same problem in Development environment, there is no problem. I can modify it with out any porblem.

That column we want to change is one of the primary key columns and also it has a unique non clustered Index.

Can you please suggest on this error?

Thank You
ChrisM@Work
ChrisM@Work
SSCrazy Eights
SSCrazy Eights (8.9K reputation)SSCrazy Eights (8.9K reputation)SSCrazy Eights (8.9K reputation)SSCrazy Eights (8.9K reputation)SSCrazy Eights (8.9K reputation)SSCrazy Eights (8.9K reputation)SSCrazy Eights (8.9K reputation)SSCrazy Eights (8.9K reputation)

Group: General Forum Members
Points: 8941 Visits: 19009
What's the name of the primary key column?
How are new values for the PK generated?
The Access application may be attempting to change the value in the PK column on the row which is currently being updated - is this intentional?

What are you doing in Dev which doesn't cause a problem - is it an update statement, a stored procedure? Does it attempt to update the PK also?

“Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
Exploring Recursive CTEs by Example Dwain Camps
VRT
VRT
SSC-Enthusiastic
SSC-Enthusiastic (186 reputation)SSC-Enthusiastic (186 reputation)SSC-Enthusiastic (186 reputation)SSC-Enthusiastic (186 reputation)SSC-Enthusiastic (186 reputation)SSC-Enthusiastic (186 reputation)SSC-Enthusiastic (186 reputation)SSC-Enthusiastic (186 reputation)

Group: General Forum Members
Points: 186 Visits: 603
Chris Morris (4/15/2009)
What's the name of the primary key column?
How are new values for the PK generated?
The Access application may be attempting to change the value in the PK column on the row which is currently being updated - is this intentional?

What are you doing in Dev which doesn't cause a problem - is it an update statement, a stored procedure? Does it attempt to update the PK also?


Thanks for your reply Chris.
I am sorry to bother you. The problem is fixed now. There is a duplicate data for that column where user is trying change it. Yes, it is a key column of composite primary key. and also it is unique non clustered index.

Unfortunately, I didn't get his duplicate when I checked that's why I kept it in forum for your help. I would have given the number wrongly while checking.

Any way, thanks for your help. I am really sorry for this.

Thank You
ChrisM@Work
ChrisM@Work
SSCrazy Eights
SSCrazy Eights (8.9K reputation)SSCrazy Eights (8.9K reputation)SSCrazy Eights (8.9K reputation)SSCrazy Eights (8.9K reputation)SSCrazy Eights (8.9K reputation)SSCrazy Eights (8.9K reputation)SSCrazy Eights (8.9K reputation)SSCrazy Eights (8.9K reputation)

Group: General Forum Members
Points: 8941 Visits: 19009
venki (4/15/2009)

Thanks for your reply Chris.
I am sorry to bother you. The problem is fixed now. There is a duplicate data for that column where user is trying change it. Yes, it is a key column of composite primary key. and also it is unique non clustered index.

Unfortunately, I didn't get his duplicate when I checked that's why I kept it in forum for your help. I would have given the number wrongly while checking.

Any way, thanks for your help. I am really sorry for this.


Hey Venki, no problem, you're very welcome. I'm glad you're resolved the problemCool

Cheers

ChrisM

“Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
Exploring Recursive CTEs by Example Dwain Camps
VRT
VRT
SSC-Enthusiastic
SSC-Enthusiastic (186 reputation)SSC-Enthusiastic (186 reputation)SSC-Enthusiastic (186 reputation)SSC-Enthusiastic (186 reputation)SSC-Enthusiastic (186 reputation)SSC-Enthusiastic (186 reputation)SSC-Enthusiastic (186 reputation)SSC-Enthusiastic (186 reputation)

Group: General Forum Members
Points: 186 Visits: 603

There is a duplicate data for that column where user is trying change it. Yes, it is a key column of composite primary key. and also it is unique non clustered index.

Any way, thanks for your help. I am really sorry for this.


I got a small concern in this issue. User is asking me to allow duplicates in the column which has Unique Non-clustered index. If I remove that index to the table then it will not be a problem for that table.

But my concern here is that if we remove that index on key column I am not sure what will be the potential issues for the application.

I don't have much experience on Database design part, so Please let me know how to know the potential impact if I remove that key column?
if any thing goes wrong, all users come back to hit my head?

Unique Non-clustered Index is just like a constraint, I believe. So if I remove that index, it means we can enter the same data again and again, but it will not affect the Primary key's functionality as it is part of a composite primary key.

Please give any suggestions to proceed?

Thank You
ChrisM@Work
ChrisM@Work
SSCrazy Eights
SSCrazy Eights (8.9K reputation)SSCrazy Eights (8.9K reputation)SSCrazy Eights (8.9K reputation)SSCrazy Eights (8.9K reputation)SSCrazy Eights (8.9K reputation)SSCrazy Eights (8.9K reputation)SSCrazy Eights (8.9K reputation)SSCrazy Eights (8.9K reputation)

Group: General Forum Members
Points: 8941 Visits: 19009
Hi Venki

Can you post the script for the table please? This will allow future posters to evaluate the problem.

“Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
Exploring Recursive CTEs by Example Dwain Camps
VRT
VRT
SSC-Enthusiastic
SSC-Enthusiastic (186 reputation)SSC-Enthusiastic (186 reputation)SSC-Enthusiastic (186 reputation)SSC-Enthusiastic (186 reputation)SSC-Enthusiastic (186 reputation)SSC-Enthusiastic (186 reputation)SSC-Enthusiastic (186 reputation)SSC-Enthusiastic (186 reputation)

Group: General Forum Members
Points: 186 Visits: 603
Chris Morris (4/22/2009)
Hi Venki

Can you post the script for the table please? This will allow future posters to evaluate the problem.


Chris,

I am sending the script for the table.

USE [WKO]
GO
/****** Object: Table [dbo].[tblCostBuildUp] Script Date: 04/22/2009 18:46:29 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblCostBuildUp](
   [CostProjCode] [nvarchar](10) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
   [CostCAOCode] [nvarchar](10) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
   [CostWorkOrder] [nvarchar](8) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
   [CostCAODescription] [nvarchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
   [CostOriginalBudget] [real] NULL CONSTRAINT [DF__Temporary__CostO__4F7CD00D] DEFAULT (0),
   [CostEstimatedCost] [real] NULL CONSTRAINT [DF__Temporary__CostE__5070F446] DEFAULT (0),
   [CostRealCost] [float] NULL CONSTRAINT [DF__Temporary__CostR__5165187F] DEFAULT (0),
   [CostOriginalHours] [smallint] NULL CONSTRAINT [DF__Temporary__CostO__52593CB8] DEFAULT (0),
   [CostEstimatedHours] [smallint] NULL CONSTRAINT [DF__Temporary__CostE__534D60F1] DEFAULT (0),
   [CostRealHours] [smallint] NULL CONSTRAINT [DF__Temporary__CostR__5441852A] DEFAULT (0),
   [CostComments] [nvarchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
   [CostStatus] [bit] NULL CONSTRAINT [DF__Temporary__CostS__5535A963] DEFAULT (0),
   [CostChargeType] [bit] NULL CONSTRAINT [DF__Temporary__CostC__5629CD9C] DEFAULT (0),
   [CostType] [nvarchar](3) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
CONSTRAINT [aaaaatblCostBuildUp4_PK] PRIMARY KEY NONCLUSTERED
(
   [CostProjCode] ASC,
   [CostCAOCode] ASC,
   [CostWorkOrder] ASC
) ON [PRIMARY]
) ON [PRIMARY]

GO
USE [WKO]
GO
ALTER TABLE [dbo].[tblCostBuildUp] WITH NOCHECK ADD CONSTRAINT [tblCostBuildUp_FK00] FOREIGN KEY([CostCAOCode])
REFERENCES [dbo].[tblCAO] ([CAOCode])
ON UPDATE CASCADE
GO
ALTER TABLE [dbo].[tblCostBuildUp] CHECK CONSTRAINT [tblCostBuildUp_FK00]
GO
ALTER TABLE [dbo].[tblCostBuildUp] WITH NOCHECK ADD CONSTRAINT [tblCostBuildUp_FK01] FOREIGN KEY([CostProjCode])
REFERENCES [dbo].[tblProject] ([ProjCode])
ON UPDATE CASCADE
ON DELETE CASCADE
GO
ALTER TABLE [dbo].[tblCostBuildUp] CHECK CONSTRAINT [tblCostBuildUp_FK01]




CostWorkOrder column is have the Unique nonClustered index. So If I remove this index will it be any problem for the rest of the tables and will the application work? This is my question, please give any clues to start from where.

Thank You
ChrisM@Work
ChrisM@Work
SSCrazy Eights
SSCrazy Eights (8.9K reputation)SSCrazy Eights (8.9K reputation)SSCrazy Eights (8.9K reputation)SSCrazy Eights (8.9K reputation)SSCrazy Eights (8.9K reputation)SSCrazy Eights (8.9K reputation)SSCrazy Eights (8.9K reputation)SSCrazy Eights (8.9K reputation)

Group: General Forum Members
Points: 8941 Visits: 19009
Interesting - the primary key consists of [CostWorkOrder] plus another two columns, but [CostWorkOrder] is also defined separately as a unique key (the DML for this isn't in your script). That's a contradiction and suggests to me that one of these is a "band aid", perhaps for performance, but more likely to support the functionality of the application. IMHO you should set up a test environment and investigate what happens when you remove the constraint.

“Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
Exploring Recursive CTEs by Example Dwain Camps
VRT
VRT
SSC-Enthusiastic
SSC-Enthusiastic (186 reputation)SSC-Enthusiastic (186 reputation)SSC-Enthusiastic (186 reputation)SSC-Enthusiastic (186 reputation)SSC-Enthusiastic (186 reputation)SSC-Enthusiastic (186 reputation)SSC-Enthusiastic (186 reputation)SSC-Enthusiastic (186 reputation)

Group: General Forum Members
Points: 186 Visits: 603
Chris Morris (4/22/2009)
Interesting - the primary key consists of [CostWorkOrder] plus another two columns, but [CostWorkOrder] is also defined separately as a unique key (the DML for this isn't in your script). That's a contradiction and suggests to me that one of these is a "band aid", perhaps for performance, but more likely to support the functionality of the application. IMHO you should set up a test environment and investigate what happens when you remove the constraint.


This is the script for index

CREATE UNIQUE NONCLUSTERED INDEX [CostWorkOrder] ON [dbo].[tblCostBuildUp] 
(
   [CostWorkOrder] ASC
) ON [PRIMARY]



Thank You
VRT
VRT
SSC-Enthusiastic
SSC-Enthusiastic (186 reputation)SSC-Enthusiastic (186 reputation)SSC-Enthusiastic (186 reputation)SSC-Enthusiastic (186 reputation)SSC-Enthusiastic (186 reputation)SSC-Enthusiastic (186 reputation)SSC-Enthusiastic (186 reputation)SSC-Enthusiastic (186 reputation)

Group: General Forum Members
Points: 186 Visits: 603
Hi,

I want to increase the column size in the table tblCostBuildUp.
I am trying to execute this DDL statement but I am getting the errors.
If I do it from SSMS then it prompts me the foreign key columns and seeking the permission from me. How can we do it from Query Analyzer?

ALTER TABLE [dbo].[tblCostBuildUp] 
ALTER COLUMN [CostWorkOrder] nvarchar(15)



errors:
Msg 5074, Level 16, State 8, Line 1
The object 'aaaaatkOrder'.
Msg 4922, Level 16, State 9, Line 1
ALTER TABLE ALTER COLUMN CostWorkOrder failed because one or more objects access this column.blCostBuildUp4_PK' is dependent on column 'CostWorkOrder'.
Msg 5074, Level 16, State 5, Line 1
The object 'FK_TimeCollection_tblCostBuildUp' is dependent on column 'CostWorkOrder'.
Msg 5074, Level 16, State 5, Line 1
The object 'FK_tblPurchaseOrder_tblCostBuildUp' is dependent on column 'CostWor



Thank You
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search