Friday, June 4, 2010

SQL @@ROWCOUNT

Returns the number of rows affected by the last statement. It will let you to do a checking on the record you updated.

If the number of rows is more than 2 billion, use ROWCOUNT_BIG.

Example
USE DB2008;
GO
UPDATE User
SET JobTitle = 'Manager'
WHERE UserID = 'u10021'
IF @@ROWCOUNT = 0
PRINT 'Warning: No rows were updated';
GO

4 comments:

je said...

The site SQL Reports has a great SQL tutorial. Highly recommended for people just getting started on SQL selects.
URL 2: http://www.sql-reports.net/2011/03/sql-select-tutorials.html

je said...

The site SQL Reports has a great SQL tutorial. Highly recommended for people just getting started on SQL selects.
URL 2: http://www.sql-reports.net/2011/03/sql-select-tutorials.html

GuildWars2Items said...

Life is too short to wake up in the morning with regrets. So, love the people who treat you right and forget about the ones who do not buy c9 gold, Life is like a hot bath. It feels good while you're in it, but the longer you stay in, the more wrinkled you get cheap c9 gold, what gets us into trouble is not what we don't know.It's what we know for sure that just ain't so c9 money.

The past is gone and static. Nothing we can do will change it.scarlet blade gold, the future is before us and dynamic. Everything we do will affect it rs gold, You laugh at mescarlet blade gold for being different , but I laugh at you for being the same.

Sudhir DBAKings said...

Nice post very helpful

dbakings