sql server - How to update and insert in T-SQL in one query -


i have database needs time time update. may happens there new data while update runs.

in mysql there option

insert ignore 

i can't find in t-sql. no problem update id 1-4 there new record id 5. update query don't work here. , when try insert data again duplicate key error.

additional infos: i've forgotten data come external sources. call api data it. there have insert these data database.

i have admit don't understand merge. solution use truncate first , insert data again. not best solution merge works, far understand it, 2 tables. have 1 table. , create table temporarly use merge , later drop table in eyes bit little table 200 records in it.

you can use merge keyword. basically, need specify column(s) on join source of data target table, , depending on whether matching (existing record) or not matching (new record), run update or insert.

reference: http://msdn.microsoft.com/en-us/library/bb510625.aspx


Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -