Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 12»»

cannot insert duplicate key row in object 'tablename' with unique index 'indexname' Expand / Collapse
Author
Message
Posted Wednesday, April 15, 2009 5:26 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Monday, July 21, 2014 9:16 PM
Points: 146, Visits: 459
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?


Thanks a lot,
Venki
Post #697397
Posted Wednesday, April 15, 2009 5:44 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Yesterday @ 6:52 AM
Points: 6,872, Visits: 14,185
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
Post #697412
Posted Wednesday, April 15, 2009 6:38 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Monday, July 21, 2014 9:16 PM
Points: 146, Visits: 459
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.


Thanks a lot,
Venki
Post #697451
Posted Wednesday, April 15, 2009 6:43 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Yesterday @ 6:52 AM
Points: 6,872, Visits: 14,185
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 problem

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
Post #697453
Posted Wednesday, April 22, 2009 6:04 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Monday, July 21, 2014 9:16 PM
Points: 146, Visits: 459

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?


Thanks a lot,
Venki
Post #702258
Posted Wednesday, April 22, 2009 6:19 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Yesterday @ 6:52 AM
Points: 6,872, Visits: 14,185
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
Post #702271
Posted Wednesday, April 22, 2009 10:01 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Monday, July 21, 2014 9:16 PM
Points: 146, Visits: 459
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.



Thanks a lot,
Venki
Post #702493
Posted Wednesday, April 22, 2009 10:36 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Yesterday @ 6:52 AM
Points: 6,872, Visits: 14,185
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
Post #702527
Posted Thursday, April 23, 2009 11:57 PM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Monday, July 21, 2014 9:16 PM
Points: 146, Visits: 459
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]



Thanks a lot,
Venki
Post #703751
Posted Tuesday, April 28, 2009 4:37 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Monday, July 21, 2014 9:16 PM
Points: 146, Visits: 459
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



Thanks a lot,
Venki
Post #705660
« Prev Topic | Next Topic »

Add to briefcase 12»»

Permissions Expand / Collapse