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

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

1、插入

1
2
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、更新

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

其他

1
2
3
4
5
//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、查询

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

  

 

创建时间:2020.07.08 

 

posted on   滔Roy  阅读(656)  评论(0编辑  收藏  举报

编辑推荐:
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
阅读排行:
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
历史上的今天:
2019-07-08 Delphi Locate函数[1] - 查询、定位
2019-07-08 奇怪桌面图标“血饮传说” 来自哪里

导航

点击右上角即可分享
微信分享提示