Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
同じテーブル構造を持つT1、T2の2つのテーブルがあります。T2にまだ存在しない場合はT1からT2に新しい行を挿入し、T2の既存のデータを主キーで更新したい場合があります。MERGEを使用して、このためのSQLを手伝ってもらえますか。
ティア
スキーマを指定せず、id が ID ではないと仮定しているため:
create table t1 (id int, txt varchar(5)) create table t2 (id int, txt varchar(5)) merge t2 as tgt using t1 as src on tgt.id = src.id when not matched by tgt then insert (id,txt) select src.id, src.txt;