The use of function Merge (update、insert、delete)
1、The use of function merge(update、insert、delete)
Example:
#1.Initialize the data
create table #test(id int ,value int); create table #test2(id int ,value int);
insert into #test values(0,0)
insert into #test values(1,1)
insert into #test values(2,2)
insert into #test values(3,3)
insert into #test2 values(1,11)
insert into #test2 values(2,22)
insert into #test2 values(5,55)
select * from #test
select * from #test2
#2.T-SQL
merge into #test p using (select id,value from #test2) np on (p.id = np.id)
--Update the record when source id matched target id
when matched then
update set p.name = np.value
--Insert the record when source id not matched target id
when not matched then
insert values (np.id,np.value)
--Delete the records when source id not matched target id and source value >= 2
when not matched by source and value>= 2 then delete;
#3.The result
select * from #test
id value
0 0
1 11
2 22
5 55
The use of function Merge (update、insert、delete)的更多相关文章
- SQL Server DML(UPDATE、INSERT、DELETE)常见用法(一)
1.引言 T-SQL(Transact Structured Query Language)是标准的SQL的扩展,是程序和SQL Server沟通的主要语言. T-SQL语言主要由以下几部分组成: 数 ...
- mybatis之@Select、@Insert、@Delete、@Param
之前学习的时候,看到别人在使用mybatis时,用到@Select.@Insert.@Delete.@Param这几个注解,故楼主研究了一下,在这里与大家分享 当使用这几个注解的时候,可以省去写Map ...
- sqlite中的replace、insert、update之前的区别
本文转自http://www.ithao123.cn/content-933827.html,在此感谢作者 android数据库操作,有两种方式,一种用android提供给我们的数据库操作函数inse ...
- Mybatis select、insert、update、delete 增删改查操作
MyBatis 是支持普通 SQL 查询,存储过程和高级映射的优秀持久层框架. MyBatis 消除了几乎所有的 JDBC 代码和参数的手工设置以及对结果集的检索.MyBatis 可以使用简单的XML ...
- mybatis的select、insert、update、delete语句
一.select <!-- 查询学生,根据id --> <select id="getStudent" parameterType="String&qu ...
- 转:mybatis——select、insert、update、delete
一.select <!-- 查询学生,根据id --> <select id="getStudent" parameterType="String&qu ...
- python3 速查参考- python基础 9 -> MySQL基础概念、数据库create、alter、insert、update、delete、select等基础命令
前置步骤: 下载一个绿色版的mysql数据库客户端连接工具 :http://wosn.net/821.html mysql平台为win7(以后会有CentOS上的) 学习目的: 掌握数据库的基本概念, ...
- MySQL中select、insert、update批量操作语句
项目中经常的需要使用批量操作语句对数据进行操作,使用批量语句的时候需要注意MySQL数据库的条件限制,这里主要是数据的大小限制,这里对批量插入.批量查找及批量更新的基础操作进行下简单的汇总. 1.批量 ...
- Android SQLiteDatabase中query、insert、update、delete方法参数说明
1.SQLiteDataBase对象的query()接口: public Cursor query (String table, String[] columns, String selection, ...
随机推荐
- Centos下删除文件名乱码文件
centos下通过rm命令来删除文件,但是如果要删除文件名乱码的文件,就不能直接使用rm命令了,因为压根就无法输出文件名来.不过借助find命令可以实现对其删除.在linux下对于每个文件都一个对应的 ...
- 生产环境搭建MySQL复制的教程(转)
[导读] 网络上有很多关于MySQL复制搭建的步骤和范例,以及手册上有一章完整的篇幅,讲述MySQL复制的原理.搭建步骤.优化等,但依然存在很多刚开始学习MySQL知识或者刚进入DBA行业的朋友咨询, ...
- 隐藏NGINX服务器名称 和版本号
隐藏NGINX服务器名称: 修改或隐藏服务器名称需要修改源码nginx.h,nginx.h在src/core/目录下 .具体操作如下: 把下面两个宏的值修改为自己设定的值,例如"NGX&qu ...
- 针对苹果最新审核要求为应用兼容IPv6-备用
在WWDC2015上苹果宣布iOS9将支持纯IPv6的网络服务.2016年初开始所有提交到App Store的应用必须支持IPv6.为确保现有的应用是兼容的,我们需要注意下面几点. 不建议使用底层的网 ...
- 无线通信技术协议-Zigbee 3.0
物联网的无线通信技术有:短距离的无线局域网通信技术和长距离的无线广域网通信技术. 短距离局域网通信技术有Zigbee.Wi-Fi.Bluetooth.Z-wave.6LoWPAN等. 长距离广域网通信 ...
- Facebook 正式开源其大数据查询引擎 Presto
Facebook 正式宣布开源 Presto —— 数据查询引擎,可对250PB以上的数据进行快速地交互式分析.该项目始于 2012 年秋季开始开发,目前该项目已经在超过 1000 名 Faceboo ...
- recovery编译学习笔记
开始建立我们要编译机器的device目录 ./build/tools/device/mkvendor.sh htc vivo ~/boot.img 需要自己配置的部分: 位置:cm/deviec/品牌 ...
- [布局]bootstrap基本标签总结2
缩略图 <div class="container"> <div class="row"> <div class="co ...
- http调试工具,linux调试工具
charles Linux下Web性能压力测试工具http_load linux 下的socket 调试工具 netcat Linux下四款Web服务器压力测试工具(http_load.webbenc ...
- 配置Delphi工具菜单 转
配置Delphi工具菜单 Delphi工具菜单是可配置的.缺省时,Delphi Tools工具菜单的菜单项为[Database Desktop].[Image Editor].[Package Col ...