4
Reply

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

Rajeev Kumar

Rajeev Kumar

2y
1.7k
0
Reply

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

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

    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.

    @@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.

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