How to Delete using INNER JOIN with SQL Server?
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不支持一次删除多张表中的数据
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?的更多相关文章
- INNER JOIN与LEFT JOIN在SQL Server的性能
我创建了INNER JOIN 9桌,反正需要很长的(超过五分钟).所以,我的民歌改变INNER JOIN来LEFT JOIN LEFT JOIN的性能较好,在首次尽管我所知道的.之后我变了,查询的速度 ...
- Microsoft SQL Server Trace Flags
Complete list of Microsoft SQL Server trace flags (585 trace flags) REMEMBER: Be extremely careful w ...
- 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 ...
- 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 ...
- SQL Server Column Store Indeses
SQL Server Column Store Indeses SQL Server Column Store Indeses 1. 概述 2. 索引存储 2.1 列式索引存储 2.2 数据编码和压缩 ...
- SQL Server基础知识
1.SQL Server表名为什么要加方括号? 这个不是必须要加,但表名或字段名如果引用了sqlserver中的关键字,数据库会不识别这到底是关键字还是表名(或字段名)时就必须要加. 比如,一个表名叫 ...
- Part 7 Joins in sql server
Joins in sql server Advanced or intelligent joins in sql server Self join in sql server Different wa ...
- SQL Server 性能调优 之运行计划(Execution Plan)调优
运行计划中的三种 Join 策略 SQL Server 存在三种 Join 策略:Hash Join,Merge Join,Nested Loop Join. Hash Join:用来处理没有排过序/ ...
- SQL Server中UPDATE和DELETE语句结合INNER/LEFT/RIGHT/FULL JOIN的用法
在SQL Server中,UPDATE和DELETE语句是可以结合INNER/LEFT/RIGHT/FULL JOIN来使用的. 我们首先在数据库中新建两张表: [T_A] CREATE TABLE ...
随机推荐
- iOS内存管理之浅见
当我们用alloc.new.copy创建对象时,对象的应用计数为1,当把这个对象retain时.引用计数+1.当对这个对象发送release消息时,引用计数-1,当对象的引用计数为0时,系统回收这个对 ...
- cocos2d-x学习日志(18) --程序是怎样開始执行与结束?
问题的由来 怎么样使用 Cocos2d-x 高速开发游戏.方法非常easy,你能够看看其自带的例程,或者从网上搜索教程,执行起第一个HelloWorld,然后在 HelloWorld 里面写相关逻辑代 ...
- 图像处理之Canny边缘检測
图像处理之Canny 边缘检測 一:历史 Canny边缘检測算法是1986年有John F. Canny开发出来一种基于图像梯度计算的边缘 检測算法,同一时候Canny本人对计算图像边缘提取学科的发展 ...
- 关于new HashMap<>(1)中1的理解(hashMap的加载因子)
新入公司,阅读代码的时候发现了一行代码,为 Map<String, String> map=new HashMap<>(1); 对于这个括号里面的1不能理解,于是查了资料,大概 ...
- oracelp---随意 记录(nvl)
1.Oracle的Nvl函数 nvl( ) 函数 从两个表达式返回一个非null 值. 语法 NVL(eExpression1, eExpression2) 参数 eExpression1, eExp ...
- [转载]移动页面所需meta元素和Viewport窗口知识点
Meta标签 vs Viewport http://www.2cto.com/kf/201409/335779.html http://blog.csdn.net/freshlover/articl ...
- 1.Configure the mongo Shell-官方文档摘录
Customize the Prompt 自定义提示 You may modify the content of the prompt by setting the variable prompt i ...
- tomcat 的 Pipeline 机制
一.server.xml 在每个容器对象里面都有一个pipeline,Pipeline就像是每个容器的逻辑总线. <Host name="localhost" appBase ...
- tfboys——tensorflow模块学习(三)
tf.estimator模块 定义在:tensorflow/python/estimator/estimator_lib.py 估算器(Estimator): 用于处理模型的高级工具. 主要模块 ex ...
- android学习二---解决ADT Buddle无法自动生成layout和res
开发环境: 1)windows 7 64位 2)adt-bundle-windows-x86_64-20140624 3)Android Development Toolkit Version: 23 ...