简体   繁体   中英

How to run multiple queries in one instance in SQL Server 2005

我想运行SELECT语句,并想对同一行执行DELETE语句,读取结果将由SQL Server响应。

WITH cte AS (
SELECT * 
FROM <mytable>
WHERE key = <mykey>)
DELETE cte
OUTPUT deleted.*;

There are many ways to skin this cat. I often preffer the one posted because is very readable. It clearly separates the SELECT into its own query expression, allowing for easily created complex queries. It deletes exactly the query result. It outputs the deleted rows.

The following is also perfectly valid and easier for simple WHERE clauses:

DELETE <mytable>
OUTPUT deleted.*
WHERE key = <mykey>;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM