Link to home
Start Free TrialLog in
Avatar of BrianMc1958
BrianMc1958

asked on

NEWBIE: Any way to ignore duplicates on INSERT?

Dear Experts,

I'm trying to insert records from one table into another table with the same key structure.  I'm using:

INSERT INTO...SELECT...FROM

So the entire insert takes place in a single statement.

But it fails if even a single record already exists in both tables.

Is there any way to say "If there's a duplicate, OVERWRITE the OLD with the NEW"?

If not, is there any way to say, "If there's a duplicate, ignore it"?

If not that either, what do I do?  Throw myself off a bridge?  How high?

Thanks,
BrianMc1958
 
Avatar of nito8300
nito8300
Flag of United States of America image

create an index and ignore duplicate values.

in EM, right click the table, go to all tasks, manage indexes add new index, select your primary key and set it to ignore duplicates...
ASKER CERTIFIED SOLUTION
Avatar of mikkilineni
mikkilineni

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of BrianMc1958
BrianMc1958

ASKER

To nito8300:  Thanks, but I should have told you I need to do this with TSQL, programatically.

To mikkilineni:  Thanks even more.  That will basically solve my problem.  But is there any reasonably simple way to have the NEW row inserted?  I believe your solution will retain the OLD row, right?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks 1,000,000.00, folks.
--BrianMc1958