2012-06-06 21 views
2

我正在使用sql2000,但我也在使用mysql和sql2008,并且对如何计算更新数量感兴趣?我确实看到哪里有更新的表,但不知道是否在正常查询中。 THX如何跟踪更新的行数

declare @updateCount as int 
set @updateCount = 0 
begin transaction 
set @updateCount = update GENIUSES set IQ=161 where IQ=86 and username like 'RetroCoder' 
print @updateCount 
if @updateCount = 1 
    commit 
else 
    rollback 

回答

4

在SQL Server:

DECLARE @updateCount INT; 
UPDATE dbo.GENIUSES set IQ=161 where IQ=86 and username like 'RetroCoder'; 
SELECT @updateCount = @@ROWCOUNT; 
+0

你有任何机会mysql的例子吗? – RetroCoder

+1

对不起,不是MySQL的人,但请[请查看ROW_COUNT()函数的文档](http://dev.mysql.com/doc/refman/5.0/en/information-functions.html#function_row-count) 。 –

3
Declare @count int 
update GENIUSES set IQ=161 where IQ=86 and username like 'RetroCoder' 
Set @count = @@Rowcount 
select @count