Example
The Table1 structure is as follows:
Id int
Name varchar (50)
Declare @ ID int
Declare @ name varchar (50)
Declare cursor1 cursor for -- defines the cursor cursor1
Select * From Table1 -- the object using the cursor (enter select text as needed)
Open cursor1 -- open a cursor
Fetch next from cursor1 into @ ID, @ name -- move the cursor down one row and put the obtained data in the variable @ ID, @ name
While @ fetch_status = 0 -- determines whether data is successfully obtained
Begin
Update Table1 set name = Name + '1'
Where [email protected] -- perform corresponding processing (enter the SQL text as needed)
Fetch next from cursor1 into @ ID, @ name -- move the cursor down one row
End
Close cursor1 -- close the cursor
Deallocate cursor1
Alter trigger [DBO]. [custom_mytextbooks_update_isopen_vocabulary]
On [DBO]. [custom_mytextbooks] for update
As
If Update ([isopen])
Begin
Declare cursorupdate cursor
Select inserted. bookid, inserted. childid, inserted. isopen isopeninserted, deleted. isopen isopendeleted from inserted inner join deleted
On inserted. myid = deleted. myid
Open cursorupdate
Declare @ bookid int, @ childid int, @ isopeninserted bit, @ isopendeleted bit
Fetch next from cursorupdate into @ bookid, @ childid, @ isopeninserted, @ isopendeleted
While @ fetch_status = 0
Begin
If @ isopendeleted = 0 and @ isopeninserted = 1
Begin
Declare @ RET int;
Exec @ ret = trigger_create_vocabulary_by_mytextbooks
@ Childid = @ childid,
@ Bookid = @ bookid
End
Fetch next from cursorupdate into @ bookid, @ childid, @ isopeninserted, @ isopendeleted
End
Close cursorupdate
Deallocate cursorupdate
End