示例一:
create table sc( sno varchar(20) not null primary key, grade int not null ) IF EXISTS (SELECT name FROM sysobjects WHERE name = 'u_sc' AND type = 'TR') DROP TRIGGER u_sc GO create trigger U_SC on sc for update As if update(grade) begin raiserror('you can not modify this column',17,1) rollback transaction end go update sc set grade=90 where sc.sno='95010'
示例二:
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'd_s' AND type = 'TR') DROP TRIGGER d_s GO create trigger d_s on student for delete As delete sc where sc.sno in (select sno from deleted) Go delete student where sno='95001'
示例三:
CREATE TRIGGER TRIGGER_GRADE ON STUDENT_INFO AFTER INSERT AS IF (SELECT SCORE FROM STUDENT_INFO )>100 OR (SELECT SCORE FROM STUDENT_INFO)<0 BEGIN PRINT '成绩要求在0-100范围之内' ROLLBACK END