0

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.

2
  • Are you trying to test different isolation levels? Commented Sep 8, 2009 at 11:07
  • Can you provide more detail - it's not clear exactly what you're trying to achieve. Commented Sep 8, 2009 at 12:59

1 Answer 1

1
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>;
Sign up to request clarification or add additional context in comments.

1 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.