Copy Code code as follows:
Create Trigger Tri_wk_csvhead_history on Wk_csvhead_history
--Declares a tri_wk_csvhead_history trigger,
The instead of INSERT---insert operation is substituted for the following action
As
Begin
DECLARE YB cursor--Declares a cursor
For
Select Noteno from inserted--the Noteno here to match the following
Open YB
DECLARE @NoteNO varchar (50)--Noteno here to match the above, define a cursor variable @noteno to manipulate insered in the Noteno table.
FETCH NEXT from YB into @NoteNO--if the noteno here matches, move the cursor
while (@ @fetch_status =0)--0 operation succeeded, -1 FETCH statement failed or the row is not in the result set,-2 fetched 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--continue to move the cursor until the @ @fetch_status is not equal to.
End
Close YB--closing cursors
Deallocate YB--Release cursor
INSERT INTO Wk_csvhead_history SELECT * from inserted
End