当前位置: 代码迷 >> Sql Server >> 关于SQL Server触发器,该怎么处理
  详细解决方案

关于SQL Server触发器,该怎么处理

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



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


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

触发器:

SQL code
create trigger to_insert on Studentinstead of insertasbegindeclare @i intselect @i = count(distinct stu_id) from Studentif @i <= 30insert into Student(...) select ... from insertedendgo
  相关解决方案