2
Reply

How the rowcount works?

sarika

sarika

17y
5.8k
0
Reply

    RowCount returns total number of rows affected by last statement execution , you can also preserve and reset rowcount anytime .

    Hi,

    @@ROWCOUNT is a system variable which will return the no of rows affected in the DML operations.

    The ROWCOUNT is one of the performance tuning mechanism. If you use the below query
    what it does if you have n number of records then it has to be sorted then it will take the 5 records.

    SELECT TOP 5 * FROM Employees ORDER BY Salary DESC

    There is an alternative way to achieve the same result.

    SET ROWCOUNT  5

    SELECT * FROM Employees ORDER BY Salary DESC

    SET ROWCOUNT 0

    It wont list the entire record. It will get stop when the resultset reach 5 for the current single connection.
    we have to set ROWCOUNT 0 for release the set count rows. Otherwise it will return the same 5 rows for that connection.

    But i think there is some impact on DML operations. Yes, if you update the records then it may restrict.