RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Language: SQL
Expertise: Intermediate
Oct 14, 2016

Using the @@rowcount Global Variable in SQL

After each Transact-SQL statement, the server sets the value of this variable to the total number of records affected by it. It can be used to verify the success of selected operations:

SQL Server sets the value of the @@rowcount variable after each T-SQL statement to the total number of records affected by the statement. The @@rowcount variable is usually used to verify success of a certain query. Here is a small example:

SELECT ID, StudentName, StudentSurname, StudentAge

INTO AugustStudents

FROM CurrentStudents

WHERE CourseFinishDate < '2016-09-01'

IF @@rowcount = 0

PRINT "No rows were copied!"
Hannes du Preez
Close Icon
Thanks for your registration, follow us on our social networks to keep up-to-date