日期:2014-05-18  浏览次数:20411 次

关于SQL Server触发器
1.在Student表中编写insert的触发器,假如每个班的学生不能超过30个,如果低于此数,添加可以完成;如果超过此数,则插入将不能实现。
2.在SC表上编写update触发器,当修改SC表中的grade字段时将其修改前后的信息保存在SC_log表中。



啦啦啦~~~大家帮帮忙啦


------解决方案--------------------
1.必须要加触发器?个人觉得在插入之前判断下比触发器好些。

触发器:

SQL code

create trigger to_insert on Student
instead of insert
as
begin
declare @i int
select @i = count(distinct stu_id) from Student
if @i <= 30
insert into Student(...) 
select ... from inserted
end
go