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 ...
随机推荐
- 如何学习TP框架
1.学习访问方法 2.控制器的写法 3.视图的写法 4.模型的写法 5.扩展类的用法 6.扩展插件的用法
- go语言发送邮件
package main import ( "fmt" "net/smtp" "strings" ) //发送邮件的逻辑函数 func Se ...
- Python踩坑:类与类对象类型参数传递与使用
前言 对初学者来说,Python确实简单好用,毕竟动态类型语言,不用定义就可以拿来用,类型之间随意转换简直不要太方便,因此Python用来写写小脚本,爬虫程序什么的,没什么问题. 不过,一旦用来开发稍 ...
- ubuntu环境初始化
0. 在Ubuntu系统中永久修改主机名也比较简单.主机名存放在/etc/hostname文件中,修改主机名时,编辑hostname文件,在文件中输入新的主机名并保存该文件即可 1.打开termini ...
- 【BZOJ4917】Hash Killer IV 乱搞
[BZOJ4917]Hash Killer IV Description 有一天,tangjz造了一个Hash函数: unsigned int Hash(unsigned int v){ un ...
- n++ ++n
n = 100 + m++ n = 100 +m; ++m n = 100 + ++m; ++m; n = 100 +m ;
- jQuery实现局部刷新页面数据绑定
今天遇到了一个问题:怎么样才能做到只刷新页面中的Repeater控件中的数据,在不用UploadPannel的情况下? 试了好多方法,无意间在看jquery文件时发现,使用load()方法即可解决此问 ...
- 让vs只启动自己想调试的站点
VS中里面多个WEB项目如何只启动一个? 每次启动时,右下角都会出现一堆的 网站有10来个.即使设置了默认启动项目, 但每次按F5启动,或者哪怕是在项目上右键启动新实例 右下角都会出现这一堆的站点 有 ...
- 接口测试工具 — postman(post请求)
1.登录接口 2.添加学生信息,这个接口是用来讲入参是json类型的 3.学生金币充值接口,这个接口是为了讲添加cookie以及身份验证的 4.上传文件接口
- Django分发控制器urls--白话聊Django系列
开始前,先上一张图,让理解Django内部的处理流程,从图中我们可以知道Django内部使用MTV架构,那今天讲的第一个部分就是控制器,在Tornado框架中叫做路由系统,负责把url映射到相应的处理 ...