The number of rows affected by the SQL statement

Source: Internet
Author: User
Tags rowcount

Global variables @ @RowCount and function rowcount_big () are used to return the number of rows affected by the previous statement. If the number of rows is greater than 2 billion, you need to use Rowcount_big ().

1,rowcount_big ():

Following a SELECT statement, this function returns the number of rows returned by the SELECT statement.

Following an inserts, UPDATE, or DELETE statement, this function returns the number of rows affected by the data Modificati On statement.

Following statements that does not return rows, such as a IF statement, this function returns 0.

2, set RowCount @Num

Set the number of rows affected by the SQL statement, and the rowcount setting is related to the session. A session will use the last set of rowcount until the session ends or the rowcount is modified.

SET ROWCOUNT 0

Cancels the rowcount limit.

3, sample Codes

SET ROWCOUNT 0--return Ten RecordsSelect *  fromdbo.test--return value is tenSelect @ @ROWCOUNT--return value is 1SelectRowcount_big ()--Alternate SolutionDeclare @n intSet @n=Ten

The number of rows affected by the SQL statement

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.