--trigger
--在SC表上建了一个触发器,查看inserted和deleted表中内容。
create trigger tri_1 on sc
for insert,update,delete
as
--declare @a int
select * from inserted
select * from deleted
go
drop trigger tri_1
go
insert into sc
values('200215122','1',87)
go
update sc
set grade=90 where sno='200215122' and cno='1'
go
select * from sc
select * from student
select * from course
go
create trigger tri_2 on student
for insert
as
select * from inserted
declare @a smallint
select @a=sage from inserted
if @a<14
update student
set sage=18 where sno=(select sno from inserted)
go
drop trigger tri_2
go
insert into student
values('200215127','liusi','男',12,'cs')
go drop table teacher
CREATE TABLE teacher
(Eno char(4) primary key,
Sal smallint,
tname char(10),
job char(8) )
go
create trigger tri_2 on teacher
for insert
as
declare @a char(8)
select @a=job from inserted
if @a='教授' and 4000>(select sal from inserted)
update teacher
set sal=4000 where eno=(select eno from inserted)
go
insert into teacher
values('1001',3000,'pro_zhang','教授')
go
select * from teacher
go