您的位置:首页技术文章
文章详情页

Sql server触发器示例

【字号: 日期:2023-10-27 17:21:52浏览:34作者:猪猪
==========================================--insert 触发器 create trigger tri_inserton studentfor insert as declare @student_id char(10)select @student_id=s.student_id from student s inner join inserted ion s.student_id=i.student_idif @student_id='0000000001' begin raiserror('不能插入1的学号!',16,8) rollback tran end go ]===============================================--update触发器 create trigger tri_updateon studentfor update as if update(student_id)begin raiserror('学号不能修改!',16,8) rollback tran end go==================================--delete触发器 create trigger tri_deleteon studentfor delete as declare @student_id varchar(10)select @student_id=student_id from deletedif @student_id='admin' begin raiserror('错误',16,8) rollback tran end================================================
标签: Sql Server 数据库