In database instead of COUNT() method in SQL SELECT query statement we can use ROWCOUNT_BIG() after simple SQL SELECT query statement.ROWCOUNT_BIG() function operates like @@ROWCOUNT and returns the number of rows affected by the last statement executed.However, the return type of data type is bigint.
SELECT statement, this function returns the number of rows returned by the SELECT statement.
INSERT, UPDATE, or DELETE statement, this function returns the number of rows affected by the data modification statement.
Syntax -
ROWCOUNT_BIG()
Examples -
SELECT * FROM Table_Name
SELECT ROWCOUNT_BIG()
@@ROWCOUNT
USE AdventureWorks2008R2;
GO
UPDATE HumanResources.Employee SET JobTitle = N'Executive' WHERE NationalIDNumber = 123456789
IF @@ROWCOUNT = 0
PRINT 'Warning: No rows were updated';
GO
It returns total number of count of SQL Statement.
Advantage -
If the number of rows returns more than 2 billion, use ROWCOUNT_BIG.
Because it returns Bigint data type which can store larger range of numbers than the int data type.
No comments:
Post a Comment