Sqlserver示例
insert
1 2 3 4 5 6 7 8 9 10 11 12 13 | create trigger tri_insert on student for insert as declare @student_idchar(10) select @student_id=s.student_id from students inner join insertedion s.student_id=i.student_id if @student_id= '0000000001' begin raiserror( '不能插入1的学号!' ,16,8) rollbacktran end go |
update
1 2 3 4 5 6 7 8 9 10 | create trigger tri_update on student for update as if update (student_id) begin raiserror( '学号不能修改!' ,16,8) rollbacktran end go |
delete
1 2 3 4 5 6 7 8 9 10 11 | create trigger tri_delete on student for delete as declare @student_idvarchar(10) select @student_id=student_id from deleted if @student_id= 'admin' begin raiserror( '错误' ,16,8) rollbacktran end |