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)
 Violation of PRIMARY KEY constraint 'NYPSignedLIst

Author  Topic 

sharona
Yak Posting Veteran

75 Posts

Posted - 2011-02-22 : 12:27:39
i receive the following error and im not sure why

Violation of PRIMARY KEY constraint 'NYPSignedLIstPK'. Cannot insert duplicate key in object 'dbo.NYPSignedLIst'.

CREATE TABLE [dbo].[NYPSignedLIst]
( [IdCode] [varchar](30) NOT NULL,
[Lname] [varchar](100) NULL,
[Fname] [varchar](100) NULL,
[Division] [varchar](100) NULL,
[PhyType] [varchar](100) NULL,
[Role] [varchar](100) NULL,
CONSTRAINT [NYPSignedLIstPK] PRIMARY KEY NONCLUSTERED
(
[IdCode] 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

INSERT INTO dbo.NYPSignedLIst
select
idcode,
lname,
fname,
division,
PhyType,
Role
from dbo.Wkly_signed_notes

yosiasz
Master Smack Fu Yak Hacker

1635 Posts

Posted - 2011-02-22 : 12:34:03
sounds like you have duplicate idcode.
Do this
select
idcode, count(*) as dup_count
from dbo.Wkly_signed_notes
group by idcode
having count(*) > 1

you will see see a row(s) with dup_count > 1. You have to deal with those rows.

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

- Advertisement -