Skip to main content

Posts

Showing posts with the label SQL RowCount

What is @@RowCount in SQL? What does this statement do @@RowCount?

The  @@ROWCOUNT  is a special variable of SQL. It will return the number of rows changed by the last statement. The @@RowCount is equal to (=) the number of rows changed by the last statement. Syntax : - @@ROWCOUNT Return Types : - INT What is the scope of @@RowCount? The @@RowCount is both the scope and connection safe and it is read only! For example as, -- DECLARE RETURN TABLE DECLARE @Return_Table TABLE (Code varchar ( 10 ) ,Message varchar ( 100 ), ID varchar ( 100 )) --UPDATE CUSTOMER QUERY UPDATE Customer SET Name = N 'Anil Singh' WHERE Id = 0786 --USE OF @@ROWCOUNT IF (@@ROWCOUNT > 0 ) BEGIN INSERT INTO @Return_Table (Code, Message, ID) SELECT 'OK' , 'SUCCESS' , SCOPE_IDENTITY() SELECT Code, Message, ID FROM @Return_Table END ELSE BEGIN INSERT INTO @Return_Table (Code, Message, ID) SELECT 'ERROR' , 'Warning - No rows updated.' , SCOPE_IDENTITY() SELECT Code, Message, ID FROM @R...