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

2 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

 

Phick1.com