I will be inserting rows using an INSERT
statement where the values are static and not already in the database. Something like:
INSERT INTO MY_TABLE (ID, NAME) VALUES(123, 'Herbert')
If MY_TABLE
already has a row with ID
equal to 123
but the NAME
is Herbie
, how can I keep the new data in the INSERT
statement (123
, Herbert
) and discard what's already in MY_TABLE
(123
, Herbie
)?
I know about the SQL Server IGNORE_DUP_KEY
setting, but I think that ignores the data in the INSERT
statement and keeps the data that's already in the table. I want the reverse.
Update
To clarify, I don't want to change the INSERT
statement. I want to keep it the same. I want to do the work on the server side somehow. Basically IGNORE_DUP_KEY
is what I want, except its keeping the wrong data.
Update 2
I think what I am trying to do is different than the duplicate question mentioned. I don't want to change the INSERT
statement at all. I want to handle it on the backend either with a SQL Server setting that I don't know about, or perhaps by creating a trigger.