Create trigger tri_wk_CSVHead_History on wk_CSVHead_History --声明一个tri_wk_CSVHead_History触发器, instead of insert ---插入操作被代替执行下面的操作 as begin declare YB cursor --声明一个游标 for select NoteNO from inserted--这里的NoteNO要和下面的匹配 open YB declare @NoteNO varchar(50)--这里的NoteNO要和上面的匹配,定义一个游标变量@NoteNO,用来操作insered表中的NoteNo. fetch next from YB into @NoteNO--这里的NoteNO要是上面的匹配,移动游标 while(@@fetch_status=0)--0操作成功,-1 FETCH 语句失败或此行不在结果集中,-2 被提取的行不存在 begin delete from wk_CSVDetail_History where NoteNO=@NoteNO delete from wk_CSVHead_History where NoteNO=@NoteNO fetch next from YB into @NoteNO --继续移动游标,直到@@fetch_status不等于时. end close YB --关闭游标 deallocate YB --释放游标 insert into wk_CSVHead_History select * from inserted end