1. 程式人生 > >新學習的命令

新學習的命令

into -- table 命令 get val date var set

1.Merge

create table sourceTable(id int ,val varchar(20))
create table targetTable (id int,val varchar(20))
insert into targetTable values(1,‘a‘),(2,‘b‘),(3,‘c‘)
insert into sourceTable values(3,‘c‘),(4,‘d‘),(4,‘d‘)

----

MERGE INTO TargetTable AS T
USING SourceTable AS S
ON T.id=S.ID
WHEN MATCHED
THEN
UPDATE SET t.Val=s.val
WHEN NOT MATCHED
THEN INSERT VALUES(s.id,s.val)
WHEN NOT MATCHED BY SOURCE
THEN DELETE;

新學習的命令