Copy codeThe Code is as follows: Create trigger tri_wk_CSVHead_History on wk_CSVHead_History
-- Declare a tri_wk_CSVHead_History trigger,
Instead of insert --- the insert operation is replaced by the following Operation
As
Begin
Declare YB cursor -- declare a cursor
For
Select NoteNO from inserted -- The NoteNO here must match the following
Open YB
Declare @ NoteNO varchar (50) -- NoteNO must match the above and define a cursor variable @ NoteNO to operate NoteNo in the insered table.
Fetch next from YB into @ NoteNO -- If NoteNO matches the above, move the cursor.
While (@ fetch_status = 0) -- The 0 operation is successful. The-1 FETCH statement fails or the row is not in the result set. The-2 extracted row does not exist.
Begin
Delete from wk_CSVDetail_History where NoteNO = @ NoteNO
Delete from wk_CSVHead_History where NoteNO = @ NoteNO
Fetch next from YB into @ NoteNO -- move the cursor until @ fetch_status is not equal.
End
Close YB -- close the cursor
Deallocate YB -- release cursor
Insert into wk_CSVHead_History select * from inserted
End