当前位置:数据库 > SQLServer >>

sql触发器delete与update操作

编写触发器:

 代码如下 复制代码
create trigger BlogDelet
on Blog
instead of delete
as
delete from Comment
where CommentBlog in (select 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触发器可参考http://www.zzzyk.com/database/mssqlserver/39336.htm

补充:数据库,Mssql 
Oracle
MySQL
Access
SQLServer
DB2
Excel
SQLite
SYBASE
Postgres
如果你遇到数据库难题:
请访问www.zzzyk.com 试试
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,