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 |
|
richardn
Starting Member
3 Posts |
Posted - 2006-05-16 : 01:28:36
|
| How to code to insert from tableA to tableB and get rid of duplicated records in tableA where the primary key is composed from many fields? I know that in MS Access the dupplicated rows are not inserted but the new rows yes. There is an option to disable warnings. Thanks,Richard |
|
|
chiragkhabaria
Master Smack Fu Yak Hacker
1907 Posts |
Posted - 2006-05-16 : 01:45:55
|
| can you post some sample data and columns which form a composite key ???If Debugging is the process of removing Bugs then i Guess programming should be process of Adding them. |
 |
|
|
jen
Master Smack Fu Yak Hacker
4110 Posts |
Posted - 2006-05-16 : 03:35:35
|
if table A has a pk, then how did you get duplicate records?for insert from a source table insert into tableB(fields....)select fields.... from tableAor i'm oversimplifying again, i tend to do that... --------------------keeping it simple... |
 |
|
|
mmarovic
Aged Yak Warrior
518 Posts |
Posted - 2006-05-16 : 04:06:37
|
| What is the criteria about which row you want to keep if there are duplicates? |
 |
|
|
richardn
Starting Member
3 Posts |
Posted - 2006-05-16 : 09:16:08
|
I mean, in table B are some records thatexist in table A, but there are some new records in A. I am interested to append the new records only, but because of the key violation the querry fails. quote: Originally posted by jen if table A has a pk, then how did you get duplicate records?for insert from a source table insert into tableB(fields....)select fields.... from tableAor i'm oversimplifying again, i tend to do that... --------------------keeping it simple...
|
 |
|
|
jen
Master Smack Fu Yak Hacker
4110 Posts |
Posted - 2006-05-16 : 09:48:33
|
| insert into tableA(fields...)select b.fields...from tableB bjoin tableA aon b.pk1<>a.pk1 and b.pk2<>a.pk2...:where pk1...n is the field member in composite key--------------------keeping it simple... |
 |
|
|
mmarovic
Aged Yak Warrior
518 Posts |
Posted - 2006-05-16 : 09:49:18
|
| [code]insert into tableB (...)select ...from tableA awhere not exists(select * from tableB b where a.pkColumn1 = b.correspondingColumn1 and a.pkColumn2 = b.correspondingColumn2)[/code] |
 |
|
|
|
|
|