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)
 populate existing table!!

Author  Topic 

agarwasa2008
Posting Yak Master

109 Posts

Posted - 2009-08-07 : 20:20:21
Need to get this done today --
populate a table with values from another table. Its not liking the word AS. Also after I remove it i get the following error to do with PK. Your input is valuable.


Error Message
=========================
Msg 2627, Level 14, State 1, Line 1
Violation of PRIMARY KEY constraint 'PK_int_upc_ean'. Cannot insert duplicate key in object 'dbo.int_upc_ean'.
The statement has been terminated.


Script:
=================
INSERT INTO dbo.int_upc_ean (frcst_altr_id, ean_cd, upc)
AS
select frcst_altr_id, ean_cd, upc
from dbo.ean_cd a
left join dbo.ext_upc_staging b
on a.frcst_altr_id = b.productCode
order by frcst_altr_id

GO

SA

SA

Vinnie881
Master Smack Fu Yak Hacker

1231 Posts

Posted - 2009-08-07 : 20:57:14
Remove the "as"

your issue is there is that a record already exists in the table that has the same column information as you are trying to import. You can not have 2 records with the same primary key.


Success is 10% Intelligence, 70% Determination, and 22% Stupidity.
\_/ _/ _/\_/ _/\_/ _/ _/- 881
Go to Top of Page

agarwasa2008
Posting Yak Master

109 Posts

Posted - 2009-08-07 : 21:10:08
I thought that too. So I deleted all the records. Still it gave me the PK error. Finally I went ahead and removed the PK feature and then I was able to populated the table. Is that how you are suppose to do?

What if you have an existing table with data (2 scenarios)

1 With duplicate possibility in the existing table. How do you have get a fianl table with only unique PK records.
2 when u know for sure there are no duplicates in the existing data as was the case for me. - obviously it did not work.



SA
Go to Top of Page
   

- Advertisement -