I want to run a SELECT statement and I want execute a DELETE statement for the same row and the read result be respond by the SQL Server.
-
Are you trying to test different isolation levels?Faiz– Faiz2009-09-08 11:07:15 +00:00Commented Sep 8, 2009 at 11:07
-
Can you provide more detail - it's not clear exactly what you're trying to achieve.Callie J– Callie J2009-09-08 12:59:22 +00:00Commented Sep 8, 2009 at 12:59
Add a comment
|
1 Answer
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>;
1 Comment
Abhishek
thanks buddy, this is useful for me but can u tell me a little bit more . i am telling you what i want to do. i am working on a chat application so i want to read the new chat and in the same instance the chat that is read should be deleted so that this not be repeated. so please tell me.