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 2005 Forums
 Transact-SQL (2005)
 Violation of PRIMARY KEY constraint

Author  Topic 

srisha
Starting Member

38 Posts

Posted - 2013-10-04 : 02:50:28
Hi Team,

I'm trying to insert multiple records into a table and getting the below error and not sure how to resolve it:



Violation of PRIMARY KEY constraint 'GLAMF_KEY_0'. Cannot insert duplicate key in object 'dbo.GLAMF'.
The statement has been terminated.

--------------------------
BY
SRISHA

srisha
Starting Member

38 Posts

Posted - 2013-10-04 : 02:55:09
This is my Query :


insert into GLAMF(ACCTID,AUDTDATE,AUDTTIME,AUDTUSER,AUDTORG,CREATEDATE,ACCTDESC,
ACCTTYPE,ACCTBAL,ACTIVESW,CONSLDSW,QTYSW,UOM,ALLOCSW,ACCTOFSET,ACCTSRTY,MCSW,SPECSW ,ACCTGRPCOD ,CTRLACCTSW,SRCELDGID ,
ALLOCTOT ,ABRKID ,YRACCTCLOS ,ACCTFMTTD,ACSEGVAL01,ACSEGVAL02,ACSEGVAL03,ACSEGVAL04,ACSEGVAL05,ACSEGVAL06,ACSEGVAL07,ACSEGVAL08,
ACSEGVAL09,ACSEGVAL10,ACCTSEGVAL,ACCTGRPSCD,POSTOSEGID,DEFCURNCOD,OVALUES,TOVALUES ,ROLLUPSW)

select ACCTID,AUDTDATE,
AUDTTIME,AUDTUSER,AUDTORG,CREATEDATE,ACCTDESC,ACCTTYPE,ACCTBAL,ACTIVESW,ISNULL(CONSLDSW,0),ISNULL(QTYSWM,0),ISNULL(UOM,0),
ISNULL(ALLOCSW,0),ISNULL(ACCTOFSET,0),ISNULL(ACCTSRTY,0),ISNULL(MCSW,1),ISNULL(SPECSW,0) ,ISNULL(ACCTGRPCOD,0) ,
ISNULL(CTRLACCTSW,0),ISNULL(SRCELDGID,0) ,ISNULL(ALLOCTOT,0) ,ISNULL(ABRKID,0) ,ISNULL(YRACCTCLOS,0) ,
ACCTFMTTD,ISNULL(ACSEGVAL01,0),ISNULL(ACSEGVAL02,0),ISNULL(ACSEGVAL03,0),ISNULL(ACSEGVAL04,0),ISNULL(ACSEGVAL05,0),
ISNULL(ACSEGVAL06,0),ISNULL(ACSEGVAL07,0),ISNULL(ACSEGVAL08,0),ISNULL(ACSEGVAL09,0),ISNULL(ACSEGVAL10,0),ISNULL(ACCTSEGVAL,0),
ISNULL(ACCTGRPSCD,0),ISNULL(POSTOSEGID,0),ISNULL(DEFCURNCOD,0),ISNULL(OVALUES,0),ISNULL(TOVALUES,0) ,ISNULL(ROLLUPSW,0)
from GLAMFSAMP where ACCTID like '%VELJJJ112%'





--------------------------
BY
SRISHA
Go to Top of Page

srisha
Starting Member

38 Posts

Posted - 2013-10-04 : 02:56:32
this Query insert only glamfsamp but glamf only given error


--------------------------
BY
SRISHA
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-10-04 : 08:12:25
whats the primary key column for 'dbo.GLAMF'
check if the select returns multiple values for it.

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

ushavellala
Starting Member

10 Posts

Posted - 2013-10-24 : 15:14:57
Primary key column should always be unique. When you insert same record again, it will throw this error.
Go to Top of Page
   

- Advertisement -