Cursor-based DELETE/UPDATE statements

Source: Internet
Author: User
If the cursor is updatable (that is, the ReadOnly parameter is not included in the definition cursor statement), you can use the cursor to DELETEUPDATE rows from the source table of the cursor data, that is, the DELETEUPDATE operation is based on the current position of the cursor. For example: -- delete the record Declarecur_DepartCursorForSelectcDeptID, cDeptN of the current row

If the cursor is updatable (that is, the Read Only parameter is not included in the definition of the cursor statement), you can use the cursor to DELETE/UPDATE rows from the source table of the cursor data, that is, the DELETE/UPDATE operation is based on the current position of the Cursor. For example: -- DELETE the records of the current row Declare cur_Depart Cursor For Select cDeptID, cDeptN

If the cursor is updatable (that is, the Read Only parameter is not included in the definition of the cursor statement), you can use the cursor to DELETE/UPDATE rows from the source table of the cursor data ,, DELETE/UPDATE operations based on the current position of the cursor;
Example:
-- Delete the record of the current row
Declare cur_Depart Cursor
For Select cDeptID, cDeptName From Department into @ DeptID, @ DeptName
Open cur_Depart
Fetch From cur_Depart into @ DeptID, @ DeptName
Delete From Department Where current of cur_Depart
-- Update the content of the current row
Declare cur_Depart Cursor
For Select cDeptID, cDeptName From Department into @ DeptID, @ DeptName
Open cur_Depart
Fetch From cur_Depart into @ DeptID, @ DeptName
Update Department Set cDeptID = '000000' + @ DeptID Where current of cur_Depart

An Update example

Create table t1 (id int) () t1, c_update_id id from t1 c_update_idc_update_id () c_update_idc_update_id c_update_idDEALLOCATE c_update_id t1t1

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.