devxlogo

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, StudentAgeINTO AugustStudentsFROM CurrentStudentsWHERE CourseFinishDate < '2016-09-01'IF @@rowcount = 0PRINT "No rows were copied!"

Charlie has over a decade of experience in website administration and technology management. As the site admin, he oversees all technical aspects of running a high-traffic online platform, ensuring optimal performance, security, and user experience.

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.