本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
取代現有資料列來執行合併操作
取代現有資料列來執行合併操作
-
建立臨時資料表,然後將它填入要合併的資料,如下列虛擬程式碼所示。
create temp table stage (like target); insert into stage select * from source where source.filter = 'filter_expression';
-
使用內部聯結搭配臨時資料表來刪除來自要刪除目標資料表的資料列。
將刪除和插入操作放置在單一交易區塊,使得若發生問題,各個項目都將能復原。
begin transaction; delete from target using stage where target.primarykey = stage.primarykey;
-
從臨時資料表插入所有資料列。
insert into target select * from stage; end transaction;
-
捨棄臨時資料表。
drop table stage;