@ @ROWCOUNT in SQL Server

Source: Internet
Author: User
Tags rowcount

The @ @ROWCOUNT in SQL Server returns the number of rows affected by the previous statement, and the return value type is int integer. if the number of rows is greater than 2 billion, you need to use Rowcount_big.

The values of the @ @ROWCOUNT and @ @ERROR variables always change after a statement is executed, so we should first save them in local variables as a basis for judgment. They reflect the impact of the last statement immediately after them!

We can usually detect whether any rows have changed by using the UPDATE, INSERT statement, and @ @ROWCOUNT.

For example:

UPDATE   dbo. EmployeeSET     =  EmpNoWHERE  1=2 IF @ @ROWCOUNT = 0    PRINT ' no data has been modified ' ; GO

The execution results are:

(0 rows affected)
No data has been modified

UPDATE   dbo. EmployeeSET     =  EmpNoWHERE  1=1-- Modify to fully execute IF@ @ROWCOUNT=0    PRINT'  No data was modified '; GO

The execution results are:

(1135 rows affected)

@ @ROWCOUNT in SQL Server

Related Article

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.