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
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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?
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks 1,000,000.00, folks.
--BrianMc1958
--BrianMc1958
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...