https://stackoverflow.com/questions/16481379/how-to-delete-using-inner-join-with-sql-server

You need to specify what table you are deleting from, here is a version with an alias:

DELETE w
FROM WorkRecord2 w
INNER JOIN Employee e
ON EmployeeRun=EmployeeNo
WHERE Company = '' AND Date = '2013-05-06'

SQL Server不支持一次删除多张表中的数据

https://stackoverflow.com/questions/783726/how-do-i-delete-from-multiple-tables-using-inner-join-in-sql-server

You can take advantage of the "deleted" pseudo table in this example. Something like:

begin transaction;

   declare @deletedIds table ( id int );

   delete t1
output deleted.id into @deletedIds
from table1 t1
join table2 t2
on t2.id = t1.id
join table3 t3
on t3.id = t2.id; delete t2
from table2 t2
join @deletedIds d
on d.id = t2.id; delete t3
from table3 t3 ... commit transaction;

Obviously you can do an 'output deleted.' on the second delete as well, if you needed something to join on for the third table.

As a side note, you can also do inserted.* on an insert statement, and both inserted.* and deleted.* on an update statement.

EDIT: Also, have you considered adding a trigger on table1 to delete from table2 + 3? You'll be inside of an implicit transaction, and will also have the "inserted." and "deleted." pseudo-tables available.

How to Delete using INNER JOIN with SQL Server?的更多相关文章

  1. INNER JOIN与LEFT JOIN在SQL Server的性能

    我创建了INNER JOIN 9桌,反正需要很长的(超过五分钟).所以,我的民歌改变INNER JOIN来LEFT JOIN LEFT JOIN的性能较好,在首次尽管我所知道的.之后我变了,查询的速度 ...

  2. Microsoft SQL Server Trace Flags

    Complete list of Microsoft SQL Server trace flags (585 trace flags) REMEMBER: Be extremely careful w ...

  3. Microsoft SQL Server Version List [sqlserver 7.0-------sql server 2016]

    http://sqlserverbuilds.blogspot.jp/   What version of SQL Server do I have? This unofficial build ch ...

  4. Microsoft SQL Server Version List(SQL Server 版本)

    原帖地址 What version of SQL Server do I have? This unofficial build chart lists all of the known Servic ...

  5. SQL Server Column Store Indeses

    SQL Server Column Store Indeses SQL Server Column Store Indeses 1. 概述 2. 索引存储 2.1 列式索引存储 2.2 数据编码和压缩 ...

  6. SQL Server基础知识

    1.SQL Server表名为什么要加方括号? 这个不是必须要加,但表名或字段名如果引用了sqlserver中的关键字,数据库会不识别这到底是关键字还是表名(或字段名)时就必须要加. 比如,一个表名叫 ...

  7. Part 7 Joins in sql server

    Joins in sql server Advanced or intelligent joins in sql server Self join in sql server Different wa ...

  8. SQL Server 性能调优 之运行计划(Execution Plan)调优

    运行计划中的三种 Join 策略 SQL Server 存在三种 Join 策略:Hash Join,Merge Join,Nested Loop Join. Hash Join:用来处理没有排过序/ ...

  9. SQL Server中UPDATE和DELETE语句结合INNER/LEFT/RIGHT/FULL JOIN的用法

    在SQL Server中,UPDATE和DELETE语句是可以结合INNER/LEFT/RIGHT/FULL JOIN来使用的. 我们首先在数据库中新建两张表: [T_A] CREATE TABLE ...

随机推荐

  1. P​H​P​制​作​姓​名​、​学​号​。​爱​好​等​窗​口

    if (radioButton1.Checked == true)                textBox2.Text = 姓名: + textBox1.Text +    性别: + radi ...

  2. 误: Apache shutdown unexpectedly解决办法

    from:http://www.wopus.org/wordpress-basic/getting-started/2536.htmlXAMPP错  2015年10月20日15:58:19 新手上路发 ...

  3. 输入一个十进制数N,将它转换成R进制数输出(运用递归实现)

    #include<stdio.h> int cnt=0;                             //用来记录每个进制存放的位置 char num[20];   //用来存 ...

  4. mybatis if test 相等的情况怎样动态拼接sql

    今天程序须要依据前台的传过来的状态推断在数据库里是取 where a>b 还是 a<b 还是 a=0 的情况  搞了一下午最后试了下 在if 里面拼接  #{status}=#{statu ...

  5. Python操作yaml文件

    基本的yaml语法 http://ansible-tran.readthedocs.io/en/latest/docs/YAMLSyntax.html YAML 还有一个小的怪癖. 所有的 YAML ...

  6. Sublime Text 3如何快速生成HTML5的头部信息和常用的快捷键

    一.快速生成HTML5的头部信息的步骤: 1.Ctrl + N,新建一个文档: 2.Ctrl + Shift + P,打开命令模式,再输入 sshtml 进行模糊匹配,将语法切换到html模式: 3. ...

  7. 【转】图解MySql命令行创建存储过程

    一 操作实例 首先登录mysql: 使用source命令,从命令行执行sql脚本,创建表: 创建第一个存储过程: 事先用DELIMITER关键字申明当前段分隔符,这样MySQL才会将";&q ...

  8. 解决Vue的表格中,expand只有某些行需要展开的问题。

    element UI里的表格里,type="expand"的话,所有行都有展开的选项,然而实际中有些行根据判断不需要展开,而element目前对这个问题还不是很友好,现在有个可以通 ...

  9. Java语言实现简单FTP软件------>FTP软件主界面的实现(四)

    首先看一下该软件的整体代码框架                        1.首先介绍程序的主入口FTPMain.java,采用了一个漂亮的外观风格 package com.oyp.ftp; im ...

  10. Matlab mser(最大极值稳定区域)

    在Matlab R2013a 和R2014a中已经实现MSER特征的提取. 一.函数detectMSERFeatures 输入的是M*N的灰度图片.可以指定阈值刻度,区域范围,感兴趣区域等参数. 输出 ...