April 15, 2009 at 5:26 am
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
April 15, 2009 at 5:44 am
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?
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
April 15, 2009 at 6:38 am
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
April 15, 2009 at 6:43 am
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:cool:
Cheers
ChrisM
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
April 22, 2009 at 6:04 am
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
April 22, 2009 at 6:19 am
Hi Venki
Can you post the script for the table please? This will allow future posters to evaluate the problem.
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
April 22, 2009 at 10:01 am
Chris Morris (4/22/2009)
Hi VenkiCan 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
April 22, 2009 at 10:36 am
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.
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
April 23, 2009 at 11:57 pm
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
April 28, 2009 at 4:37 am
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
April 28, 2009 at 11:59 pm
venki (4/28/2009)
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
Please guide me yar. How to change the column size in query analyzer, not in SSMS?
Thank You
December 4, 2010 at 5:12 am
Cannot insert duplicate key row in object 'tablename' with unique index 'indexname' in sql means?
April 30, 2013 at 8:34 am
April 30, 2013 at 8:41 am
logicinside22 (4/30/2013)
http://connect.microsoft.com/SQLServer/feedback/details/434632/#details%5B/quote%5D
Not really. The connect item refers to a bug which can only be observed if a very specific set of conditions are met.
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
May 1, 2013 at 8:41 am
VRT (4/28/2009)
Please guide me yar. How to change the column size in query analyzer, not in SSMS?
You can't alter a column that is part of the primary key or that is referenced as a foreign key by another table. You have to drop the primary key and foreign key(s) before you can alter the column.
Jason Wolfkill
Viewing 15 posts - 1 through 14 (of 14 total)
You must be logged in to reply to this topic. Login to reply