The table1 structure is as follows2Idint 3Namevarchar( -) 4 5 Declare @id int 6 Declare @name varchar( -) 7 DeclareCursor1cursor for --Defining Cursors Cursor1 8 Select * fromTable1--objects using cursors (fill in select text as required) 9 OpenCursor1--Open CursorTen One Fetch Next fromCursor1 into @id,@name --move the cursor down by 1 rows to get the data into the previously defined variable @id, @name A - while @ @fetch_status=0 --determine if the data was successfully obtained - begin the UpdateTable1SetName=Name+'1' - whereId=@id --Handle it accordingly (fill in the SQL text as needed) - - Fetch Next fromCursor1 into @id,@name --move the cursor down by 1 rows + End - + CloseCursor1--Close Cursors A deallocateCursor1
Cursor General format:
DECLARECursor nameCURSOR for SELECTField1,Field2,Field3,... FromTable nameWHERE ...
OPENCursor name
FETCH NEXT fromCursor nameIntoVariable name1,Variable name2,Variable name3,...
While @ @FETCH_STATUS =0
BEGIN
SqlStatement execution procedure... ...
FETCH NEXT fromCursor name1, Variable name 2, Variable name 3,...
END
< Span style= "Font-family:times New Roman;" >close cursor name
deallocate Reference: http://www.cnblogs.com/Gavinzhao/archive/2010/07/14/ 1777644.html
Use of SQL cursor