| Author |
Topic |
|
psitba
Starting Member
6 Posts |
Posted - 2009-09-22 : 14:51:28
|
I'm trying to copy data from one table to another table with almost the same columns name... but i'm getting this error msg:The statement has been terminated.Msg 2627, Level 14, State 1, Line 1Violation of PRIMARY KEY constraint 'PK_tEEOCategory'. Cannot insert duplicate key in object 'dbo.tEEOCategory'.my statement:INSERT INTO PSCHCS03.PS5293Sample.dbo.tEEOCategory(EEOCategoryCode,EEOCategoryDescription,SortOrder,EEOCategoryGUID,EOSurveySortOrder,InactiveFlag,[RowVersion])selectEEOCategoryCode,EEOCategoryDescription,SortOrder,EEOCategoryGUID,EOSurveySortOrder,InactiveCodeFlag,1 AS [RowVersion]fromtEEOCategoryselect * from tEEOCategoryPlease help!! |
|
|
Skorch
Constraint Violating Yak Guru
300 Posts |
Posted - 2009-09-22 : 15:11:28
|
| You're trying to insert a EEOCategoryCode which already exists in the table, that's why you're getting a primary key violation.Some days you're the dog, and some days you're the fire hydrant. |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
psitba
Starting Member
6 Posts |
Posted - 2009-09-22 : 16:07:41
|
Here's my DDLCREATE TABLE [dbo].[tEEOCategory]( [EEOCategoryCode] [dbo].[shrsCode] NOT NULL, [EEOCategoryDescription] [dbo].[shrsDescription] NOT NULL, [SortOrder] [nvarchar](15) NULL, [EEOCategoryGUID] [uniqueidentifier] ROWGUIDCOL NOT NULL, [EOSurveySortOrder] [nvarchar](15) NULL, [InactiveFlag] [dbo].[shrsFlag] NOT NULL, [RowVersion] [int] NOT NULL, CONSTRAINT [PK_tEEOCategory] PRIMARY KEY CLUSTERED ( [EEOCategoryCode] ASC)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY], CONSTRAINT [RG_tEEOCategory] UNIQUE NONCLUSTERED ( [EEOCategoryGUID] ASC)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]) ON [PRIMARY]let me try the UPDATE ..thanks for the suggestion |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
X002548
Not Just a Number
15586 Posts |
Posted - 2009-09-22 : 16:26:46
|
| [CODE]INSERT INTO PSCHCS03.PS5293Sample.dbo.tEEOCategory ( EEOCategoryCode , EEOCategoryDescription , SortOrder , EEOCategoryGUID , EOSurveySortOrder , InactiveFlag , [RowVersion])SELECT EEOCategoryCode , EEOCategoryDescription , SortOrder , EEOCategoryGUID , EOSurveySortOrder , InactiveCodeFlag 1 AS [RowVersion] FROM tEEOCategory WHERE EEOCategoryGUID NOT IN ( SELECT EEOCategoryGUID FROM PSCHCS03.PS5293Sample.dbo.tEEOCategory)[/CODE]Brett8-)Hint: Want your questions answered fast? Follow the direction in this linkhttp://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspxAdd yourself!http://www.frappr.com/sqlteam |
 |
|
|
psitba
Starting Member
6 Posts |
Posted - 2009-09-22 : 16:39:08
|
quote: Originally posted by X002548 You do know that you are taking everything from that table, tEEOCategoryBrett8-)
Yes, I figure it wouldn't hurt and just in case you ask me for more stuff. |
 |
|
|
X002548
Not Just a Number
15586 Posts |
Posted - 2009-09-22 : 16:41:40
|
Well, what I meant was...Are you sure that none of the key data exists in the table you are inserting into?It appears that it does...Run this and tell us what it gives youSELECT COUNT(*) FROM tEEOCategory WHERE EEOCategoryGUID IN ( SELECT EEOCategoryGUID FROM PSCHCS03.PS5293Sample.dbo.tEEOCategory) Brett8-)Hint: Want your questions answered fast? Follow the direction in this linkhttp://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspxAdd yourself!http://www.frappr.com/sqlteam |
 |
|
|
psitba
Starting Member
6 Posts |
Posted - 2009-09-22 : 16:57:47
|
| it give me '29' |
 |
|
|
X002548
Not Just a Number
15586 Posts |
Posted - 2009-09-22 : 17:02:44
|
| Well that mean that 29 rows of data already exists with that key in the table you are trying to insert into, and that won't workAnd what doesSELECT COUNT(*) FROM tEEOCategorySELECT COUNT(*) FROM PSCHCS03.PS5293Sample.dbo.tEEOCategory)Give you?Brett8-)Hint: Want your questions answered fast? Follow the direction in this linkhttp://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspxAdd yourself!http://www.frappr.com/sqlteam |
 |
|
|
psitba
Starting Member
6 Posts |
Posted - 2009-09-22 : 17:07:41
|
| SELECT COUNT(*) FROM tEEOCategory = 29SELECT COUNT(*) FROM PSCHCS03.PS5293Sample.dbo.tEEOCategory = 29 |
 |
|
|
psitba
Starting Member
6 Posts |
Posted - 2009-09-22 : 17:35:37
|
quote: Originally posted by psitba SELECT COUNT(*) FROM tEEOCategory = 29SELECT COUNT(*) FROM PSCHCS03.PS5293Sample.dbo.tEEOCategory = 29
Brett, Thank you very much for your help I know what need to be done now. |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
|