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.
| Author |
Topic |
|
macsterling
Yak Posting Veteran
56 Posts |
Posted - 2008-07-22 : 23:15:57
|
| I am updating an SQL that among a lot of things inserts about 6,000 rows in a table. At some point I am getting a duplicate key error. I have selected the data from the source filed and ordered it the same way it needs to be for the insert. I am then looking for the duplicate (manually!) After about 1/2 hour I go blind and have to start over. I am an old mainframe DB2 programmer and in COBOL (a dirty word I know) you can display anything you want as you go along, and find out exactly where and what the problem is. Is there any way to find out what the duplicate record is? |
|
|
rmiao
Master Smack Fu Yak Hacker
7266 Posts |
Posted - 2008-07-22 : 23:24:11
|
| Try load data to staging table first then move to target table, can add more control that way. |
 |
|
|
macsterling
Yak Posting Veteran
56 Posts |
Posted - 2008-07-23 : 00:15:19
|
| Would I not get the same error putting it in a staging (temp?) table/ |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-07-23 : 04:47:42
|
quote: Originally posted by macsterling Would I not get the same error putting it in a staging (temp?) table/
nope. as long as you dont have any primary key or unique key defined on it. once you get data on staging compare this with your master table and insert only those records which is not present in master.use either of below approach for it:-insert into masterselect s.* from staging sleft join master mon m.unique field=s.unique fieldwhere m.unique field is null or insert into masterselect * from staging where uniquefield not in (select uniquefield from master) |
 |
|
|
macsterling
Yak Posting Veteran
56 Posts |
Posted - 2008-07-23 : 11:38:45
|
| Thanks! |
 |
|
|
|
|
|