Introduction to SQL Server cursors

Source: Internet
Author: User

Cursor instances:

Declare mycusror Cursor Scroll

For Select * from Master_goods Order by Goodsid

Open MyCursor

Fetch next from MyCursor to @GoodsCode, @GoodsName

while (@ @Fetch_Status = 0)

Begin

Begin

Select @GoodsCode = Convert (Char (), @GoodsCode)

Select @GoodsName = Convert (Char (), @GoodsName)

PRINT @GoodsCode + ': ' + @GoodsName

End

Fetch Next from MyCursor

Into @GoodsCode, @GoodsName

End

Close MyCursor

Deallocate mycursor

The data method for modifying the current cursor is as follows:

UpDate master_goods Set goodsname = ' yangyang8848 ' Where current of mycursor;

The method to delete the current cursor row data is as follows:

Delete from Master_goods Where Current of MyCursor

Select @ @CURSOR_ROWS to get the number of rows of data that exist in the current cursor.

Note: This variable is a global variable on a connection, so it only corresponds to the last cursor that was opened.

Introduction to SQL Server cursors

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.