sql server - SQLServer 2008 UPSERT merge without repeating the values -
i have created pseudo upsert statement works, due fact data insert or update might quite large, in order reduce network bandwidth, define data updated or inserted once.
for brevity, in example have incuded 2 fields , both have short data length, in real system there may dozens of fields, , of them may long.
merge part t using (select id) s on(s.id = t.id) when matched update set id='abcd-000',description='new description' when not matched insert (id,description) values('abcd-000','new description');
in example, id unique, if therecord exists should updated, if not exist new record should inserted.
you can use this:
merge part t using ( select 'abcd-000' id, 'new description' newdescription ) s on (s.id = t.id) when matched update set t.description=s.newdescription when not matched insert (id,description) values(s.id, s.newdescription);
also, no need set id='abcd-000'
on when matched update
, because of mathcing condition s.id = t.id
already.
Comments
Post a Comment