The @ @ROWCOUNT function in SQL

Source: Internet
Author: User

Returns the number of rows affected by the previous statement. If the number of rows is greater than 2 billion, use Rowcount_big.

Grammar

@ @ROWCOUNT


return type

Int


Notes

Transact-SQL statements can set the value of the @ @ROWCOUNT in the following ways:


Sets the @ @ROWCOUNT to the number of rows affected or read . Rows can be sent to the client or not sent.
Keep the @ @ROWCOUNT in the previous statement execution.
Resets the @ @ROWCOUNT to 0 but does not return the value to the client.

A statement that performs a simple assignment always sets the @ @ROWCOUNT value to 1. No rows are sent to the client. Examples of these statements are SET @local_variable, RETURN, READTEXT, and a SELECT statement without a query, such as Select GETDATE () or select ' Generic Text '.

The statement that performs the assignment in the query or uses RETURN will set the @ @ROWCOUNT value to the number of rows that are affected by the query or read by the query , for example: SELECT @local_variable = C1 from t1.

The Data Manipulation language (DML) statement sets the @ @ROWCOUNT value to the number of rows affected by the query and returns that value to the client. The DML statement does not send any rows to the client.

DECLARE CURSOR and FETCH set the @ @ROWCOUNT value to 1.

The EXECUTE statement retains the previous @ @ROWCOUNT.

Statements such as use, SET <option>, deallocate cursor, CLOSE cursor, BEGIN TRANSACTION, or COMMIT TRANSACTION reset the ROWCOUNT value to 0.


Example

The following example executes
UPDATE
Statement and use
@ @ROWCOUNT
To detect if any of the rows have changed.

Use ADVENTUREWORKS2008R2;
GO UPDATE humanresources.employee SET jobtitle = N ' Executive '
GO
&NBSP;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.