SQL SERVER 两表比对更新、插入字段写法

SQL SERVER 两表比对更新、插入字段写法

1、插入

insert into 表1 (表1字段1,表1字段2) select 表2字段1,表2字段2 from 表2
insert into table1 (column1,column2,...) select column1,column2,... from table2

  

2、更新

update table1,table2 set table1.column1=table2.column1 where table1.column2=table2.column2

其他

//1
update table1 set field1=table2.field1,field2=table2.field2 from table2 where table1.id=table2.id

//2
update table1 set field1=(select top 1 field1 from table2 where table2.id=table1.id) where table1.id in (condition)

  

3、查询

select * from table1 where ID not in(select ID from table2) 

  

创建时间:2020.07.08 

原文地址:https://www.cnblogs.com/guorongtao/p/13267427.html