首頁 >資料庫 >mysql教程 >sql触发器delete与update操作

sql触发器delete与update操作

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB原創
2016-06-07 17:49:001122瀏覽

本文章讲述最简单的sql 触发器的delete和update操作,有需要学习的同学可以参考一下本文章。

编写:

 代码如下 复制代码
create trigger BlogDelet
on Blog
instead of delete
as
delete from Comment
where CommentBlog in ( Id from deleted)

创建一个Update触发器:

 代码如下 复制代码

     Create Trigger truStudent
       On Student                         --在Student表中创建触发器
       for Update                          --为什么事件触发
     As                                        --事件触发后所要做的事情
       if Update(StudentID)           
       begin

         Update BorrowRecord
           Set StudentID=i.StudentID
           From BorrowRecord br , Deleted   d ,Inserted i      --Deleted和Inserted临时表
           Where br.StudentID=d.StudentID

       end      

 

更多详细的关于sql触发器可参考

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn