RetroCoder
RetroCoder

Reputation: 2685

How do I track number of rows updated

I'm using sql2000 but I'm also using mysql, and sql2008 and am interested in how to count the number of updates I justed updated? I do see where there is an updated table but not sure if that's within a normal query. 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

Upvotes: 2

Views: 131

Answers (2)

user1425057
user1425057

Reputation:

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

Upvotes: 3

anon
anon

Reputation:

In SQL Server:

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

Upvotes: 4

Related Questions