How to Delete using INNER JOIN with SQL Server?
2024-10-19 16:34:30
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.
最新文章
- C#检测本地网络状态
- Atitit (Sketch Filter)素描滤镜的实现  图像处理  attilax总结
- HDU4930 Fighting the Landlords 模拟
- 缓存技术比拼:Redis与Memcached的同与不同
- 管窥MVVMLight Command参数绑定和事件传递
- Effective Java之避免创建不必要的对象
- 迷宫问题python实现(靠右手摸墙)
- 连载:面向对象葵花宝典:思想、技巧与实践(33) - ISP原则
- Windows Ubuntu Bash申请免费通配符证书(Let's Encrypt)并绑定IIS
- vue学习记录③(路由)
- 什么是 IP 隧道,Linux 怎么实现隧道通信?
- MACE移植要求
- 已使用.netframework,version=v4.6.1 而不是目标框架netcoreapp,version=v2.1 还原包,此包可能与项目不完全兼容
- Pytorch Visdom
- Linux文件系统深度讨论【转】
- unigui1404在delphi10.2.2安装
- docker-部署elk-6.1.3
- Java基础-Java中的并法库之线程池技术
- 004.SMB之guest级别配置
- java.lang.Exception: Socket bind failed: [730048]
热门文章
- Mongo同步数据到Elasticsearch
- LIS(模板)
- Unit redis-server.service is masked.
- 删除datatable中的行
- JS添加标签
- Docker容器/镜像查看及删除操作
- 剑指offer 面试39题
- python默认参数不能定义为可变对象类型
- Python基础(18)_面向对象程序设计2(反射、__str__、__del__、__item__系列)
- vlc做转发的命令