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)的更多相关文章

  1. SQL Server DML(UPDATE、INSERT、DELETE)常见用法(一)

    1.引言 T-SQL(Transact Structured Query Language)是标准的SQL的扩展,是程序和SQL Server沟通的主要语言. T-SQL语言主要由以下几部分组成: 数 ...

  2. mybatis之@Select、@Insert、@Delete、@Param

    之前学习的时候,看到别人在使用mybatis时,用到@Select.@Insert.@Delete.@Param这几个注解,故楼主研究了一下,在这里与大家分享 当使用这几个注解的时候,可以省去写Map ...

  3. sqlite中的replace、insert、update之前的区别

    本文转自http://www.ithao123.cn/content-933827.html,在此感谢作者 android数据库操作,有两种方式,一种用android提供给我们的数据库操作函数inse ...

  4. Mybatis select、insert、update、delete 增删改查操作

    MyBatis 是支持普通 SQL 查询,存储过程和高级映射的优秀持久层框架. MyBatis 消除了几乎所有的 JDBC 代码和参数的手工设置以及对结果集的检索.MyBatis 可以使用简单的XML ...

  5. mybatis的select、insert、update、delete语句

    一.select <!-- 查询学生,根据id --> <select id="getStudent" parameterType="String&qu ...

  6. 转:mybatis——select、insert、update、delete

    一.select <!-- 查询学生,根据id --> <select id="getStudent" parameterType="String&qu ...

  7. python3 速查参考- python基础 9 -> MySQL基础概念、数据库create、alter、insert、update、delete、select等基础命令

    前置步骤: 下载一个绿色版的mysql数据库客户端连接工具 :http://wosn.net/821.html mysql平台为win7(以后会有CentOS上的) 学习目的: 掌握数据库的基本概念, ...

  8. MySQL中select、insert、update批量操作语句

    项目中经常的需要使用批量操作语句对数据进行操作,使用批量语句的时候需要注意MySQL数据库的条件限制,这里主要是数据的大小限制,这里对批量插入.批量查找及批量更新的基础操作进行下简单的汇总. 1.批量 ...

  9. Android SQLiteDatabase中query、insert、update、delete方法参数说明

    1.SQLiteDataBase对象的query()接口: public Cursor query (String table, String[] columns, String selection, ...

随机推荐

  1. 基于.NET MVC的高性能IOC插件化架构(一)

    最近闲下来,整理了下最近写的代码,先写写架构,后面再分享几个我自己写的插件 最近经过反复对比,IOC框架选择了Autofac,原因很简单,性能出众,这篇博文是我的各大IOC框架的性能测试:http:/ ...

  2. Xcode 如何设置 自动内存管理 转换为 手动内存管理

    建议使用自动内存管理 ARC. 如果不想自动内存管理,可以在build phases 下的compile sources 中找到不想自动管理的.m文件 ,给它加compiler flags 为 -fn ...

  3. Ubuntu 查看和杀死进程[转]

    今天在netbeans中关闭webrick时,发现没有关闭掉,打入localhost:3000 依然显示页面,发现无法从nb中再次关闭只有进入ubuntu的进程下关闭查看进程:1法,ps -e 命令 ...

  4. 深入理解CSS选择器优先级的计算

    选择器的优先级关系到元素应用哪个样式.在CSS2.1的规范(http://www.w3.org/TR/2009/CR-CSS2-20090908/cascade.html#specificity)中是 ...

  5. nosql newsql

    http://www.cnblogs.com/end/archive/2011/10/19/2217244.html http://www.csdn.net/article/2011-09-26/30 ...

  6. MFC的杂七杂八

    1.判断焦点当前所在控件 2.动态移动控件位置 3.GDI+绘制文字 4.编辑框跳变显示 5.最大化显示 6.Uint uFormat常用值 7.获取菜单个数 8.添加气泡提示 9.编辑框输入时响应函 ...

  7. 【转】24. android dialog ——ProgressDialog 进度条对话框详解

    原文网址:http://blog.csdn.net/jamesliulyc/article/details/6375598 首先在onCreateDialog方法里创建一个ProgressDialog ...

  8. java--字节数组输入、输出流

    在java网络编程中,字节数组很重要,它可以传输任何资料(文本,音频,视频,图片等),因此掌握字节数组和其它数据类型的相互转化尤为重要. 示例代码: package com.lky.util; imp ...

  9. 禁止浏览器发送referer

    有时候我们需要把其他网站的链接爬取到自己网站,比如各种信息集成网站. 有些网站会有防盗链的措施,我们无法“引用”他人链接(这种情况暂时不考虑),如果网站没有防盗链措施,那就恭喜了! 但是,为了不让“被 ...

  10. solr 3.5 配置及server设置

    一.solr 的简单介绍 Apache Solr 是一个开源的搜索server.Solr 使用 Java 语言开发,主要基于 HTTP 和 Apache Lucene 实现.Apache Solr 中 ...