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