I can't seem to figure out how to select the number of previously deleted records with SQL Server 2008. Is it something like this?
DELETE FROM [table] WHERE [id]=10
SELECT SCOPE_IDENTITY()
Use SELECT @@ROWCOUNT immediately after the DELETE statement. You can read more about @@ROWCOUNT on MSDN:
@@ROWCOUNTReturns the number of rows affected by the last statement.
Remarks
...
Data manipulation language (DML) statements set the
@@ROWCOUNTvalue to the number of rows affected by the query and return that value to the client. The DML statements may not send any rows to the client.
Note that I say "immediately after" because other statements can change the value of @@ROWCOUNT, even if they don't affect rows, per se:
DECLARE CURSORandFETCHset the@@ROWCOUNTvalue to 1....
Statements such as
USE,SET <option>,DEALLOCATE CURSOR,CLOSE CURSOR,BEGIN TRANSACTIONorCOMMIT TRANSACTIONreset theROWCOUNTvalue to 0.
You can also SET NOCOUNT OFF.
Remarks
When SET NOCOUNT is ON, the count (indicating the number of rows affected by a Transact-SQL statement) is not returned. When SET NOCOUNT is OFF, the count is returned.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With