我似乎不知道如何使用 SQL Server 2008 选择以前删除的记录数。是这样的吗?
DELETE FROM [table] WHERE [id]=10
SELECT SCOPE_IDENTITY()
最佳答案
使用SELECT @@ROWCOUNT
紧接着 DELETE
陈述。您可以read more about @@ROWCOUNT
on MSDN :
@@ROWCOUNT
Returns the number of rows affected by the last statement.
Remarks
...
Data manipulation language (DML) statements set the
@@ROWCOUNT
value 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.
请注意,我说“立即之后”,因为其他语句可以更改 @@ROWCOUNT
的值,即使它们本身不影响行:
DECLARE CURSOR
andFETCH
set the@@ROWCOUNT
value to 1....
Statements such as
USE
,SET <option>
,DEALLOCATE CURSOR
,CLOSE CURSOR
,BEGIN TRANSACTION
orCOMMIT TRANSACTION
reset theROWCOUNT
value to 0.
关于sql - 使用 t-SQL 选择已删除记录的数量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14300671/