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, ...
随机推荐
- CSS强制图片大小
相信大家做网页时经常会碰到大分辨率的图片会把表格涨破以致漂亮的网页面目全非,但只要使用以下的CSS语句即可解决. 该CSS的功能是:大于600的图片自动调整为600显示. <style type ...
- 【行为型】Command模式
命令模式是指将用户的请求封装成(命令)对象,从而可将用户不同的请求进行参数化.对这些请求排序或记录请求日志.以及支持回滚恢复操作.记得以前刚开始使用Photoshop时,就发现它的操作历史记录面板特别 ...
- 摇滚吧HTML5!有声前端交互!(Hello, Jsonic!)
软件工程师们摆弄1和0编写他们的乌托邦,音乐人门把玩12平均律上的音符构筑他们的伊甸园.最近,我偶然看了<蓝色骨头>这部电影,片中的男主角是位黑客,同时又兼具音乐创作的才华.在现实生活中, ...
- 探讨VMP 2.12.3 导入表修复
壳版本:VMProtect.Ultimate.2.12.3 样本:notepad.exe 目的:IAT修复 作者:MrWrong 标题:探讨VMP 2.12.3 导入表修复 只是感兴趣,没有其他目的. ...
- 标签 Attribute
在一个类上面放一个标签,可以用来表示一些特定规则,比如某个对象的某个属性不想被json化,那么我们在它头上放个标签就行了,或是做ORM时指定某个Class对应的table名字等. 最后标签是通过反射来 ...
- 设置tableWidget->verticalScrollBar()的属性
tableWidget->verticalScrollBar()->setStyleSheet("QScrollBar{background:rgb(255,255,0); wi ...
- 难得一见的HTML5动画欣赏及源码下载
今天要给大家分享一些很酷的HTML5动画演示,并且提供源代码的下载.大部分HTML5动画都是通过canvas实现,当然也有基于SVG的,尤其是第一个,看起来很简单,但是创意却不错. 1.HTML5梦幻 ...
- AsyncTask和Handler的优缺点比较
AsyncTask实现的原理和适用的优缺点 AsyncTask,是android提供的轻量级的异步类,可以直接继承AsyncTask,在类中实现异步操作,并提供接口反馈当前异步执行的程度(可以通过接口 ...
- java模拟http post
我们将使用java.net.URLConnection来完成一次post请求,假设要post数据到http://localhost:8080/doSome上: URLConnection urlCon ...
- codeforces 100548F (西安现场赛F题):容斥原理
题目大意: 对n个排成一排的物品涂色,有m种颜色可选. 要求相邻的物品颜色不相同,且总共恰好有K种颜色,问所有可行的方案数 分析: 从m种颜色中选出k种,有c(m,k)种方法,那么我们只用考虑 k种颜 ...