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.
CREATE PROCEDURE UpdateEmployees @LastName nvarchar(50), @Salary decimal(10,2)ASBEGIN UPDATE Employees SET Salary = @Salary WHERE LastName = @LastName SELECT @@ROWCOUNT AS NumRowsAffectedEND
CREATE PROCEDURE UpdateEmployees
@LastName nvarchar(50),
@Salary decimal(10,2)
AS
BEGIN
UPDATE Employees
SET Salary = @Salary
WHERE LastName = @LastName
SELECT @@ROWCOUNT AS NumRowsAffected
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.