Rajeev Kumar
What is use of @@ROWCOUNT in T-Sql with Procdure?

What is use of @@ROWCOUNT in T-Sql with Procdure?

By Rajeev Kumar in SQL Server on Jan 06 2023
  • Tuhin Paul
    Apr, 2023 15

    1. CREATE PROCEDURE UpdateEmployees
    2. @LastName nvarchar(50),
    3. @Salary decimal(10,2)
    4. AS
    5. BEGIN
    6. UPDATE Employees
    7. SET Salary = @Salary
    8. WHERE LastName = @LastName
    9. SELECT @@ROWCOUNT AS NumRowsAffected
    10. END

    In this stored procedure, we are updating the Salary column of the Employees table for all employees with the specified LastName. After the UPDATE statement, we are using @@ROWCOUNT to return the number of rows that were affected by the UPDATE statement.

    • 0
  • Tuhin Paul
    Apr, 2023 15

    @@ROWCOUNT is a system function in T-SQL that returns the number of rows affected by the last statement executed.

    In the context of a stored procedure, @@ROWCOUNT can be used to determine the number of rows affected by a particular SQL statement within the procedure. For example, if you have an UPDATE statement that modifies some rows in a table, you can use @@ROWCOUNT to determine the number of rows that were actually updated.

    • 0
  • Munib Butt
    Jan, 2023 12

    @@ROWCOUNT means the number of rows affected after an update or read.

    • 0


Most Popular Job Functions


MOST LIKED QUESTIONS