Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Cannot insert duplicate key in object

Author  Topic 

teamjai
Yak Posting Veteran

52 Posts

Posted - 2012-04-27 : 01:27:01
i create a table
using SQL server

<code>CREATE TABLE [dbo].[cMat_SalesOffice_ITE_C](
[RSRC] [smallint] NOT NULL,
[Deleted] [bit] NOT NULL,
[DateNew] [datetime] NOT NULL,
[DateChanged] [datetime] NULL,
[UserNew] [int] NOT NULL,
[UserChanged] [int] NULL,
[camosGUID] [varchar](36) NOT NULL,
[SalesOfficeGUID] [varchar](36) NULL,
[ValidFrom] [datetime] NULL,
[ValidTo] [datetime] NULL,
[Factor] [decimal](18, 2) NULL,
[ProductType_Class] [nvarchar](50) NULL,
[BusinessType] [nvarchar](50) NULL,
[ReadAccess] [int] NOT NULL,
[WriteAccess] [int] NOT NULL,
CONSTRAINT [PK_cMat_SalesOffice_ITE_C] PRIMARY KEY CLUSTERED
(
[camosGUID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO

ALTER TABLE [dbo].[cMat_SalesOffice_ITE_C] WITH CHECK ADD CONSTRAINT [FK_cMat_SalesOffice_ITE_C_cMat_SalesOffice_ITE_C] FOREIGN KEY([SalesOfficeGUID])
REFERENCES [dbo].[cMat_SalesOffice_C] ([camosGUID])
GO</code>
While saving the second record , i got an error, pls ref below error msg

"Violation of PRIMARY KEY constraint" and cannot insert duplicate key in object

pls help me

yosiasz
Master Smack Fu Yak Hacker

1635 Posts

Posted - 2012-04-27 : 03:01:12
sounds like you are trying to enter a non unique camosGUID when that value already exists in the table. you put a unique constraint on that field as PRIMARY KEY CLUSTERED. hence it is doing exactly what you have asked it to do


<><><><><><><><><><><><><><><><><>
If you don't have the passion to help people, you have no passion
Go to Top of Page

vinu.vijayan
Posting Yak Master

227 Posts

Posted - 2012-04-27 : 04:46:00
Please post both your insert statements with the exact data you were trying to insert.
You are inserting the same item as GUID in the second insert.

N 28° 33' 11.93148"
E 77° 14' 33.66384"
Go to Top of Page
   

- Advertisement -