USE [Jiao]
GO
/****** Object: Trigger [dbo].[tri_ds_insert] Script Date: 01/14/2015 22:22:35 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER TRIGGER [dbo].[tri_ds_insert]
ON [dbo].[t_DynamicScore]
for INSERT
AS
BEGIN
--定义变量
declare @Teaching int,--教学总分
@Environmental int,--环境总分
@Cars int,--车辆总分
@Teacher int,--教练总分
@sumsum int,--评分总条数
@teacsum int,--对某位教练评论的总条数
@SchoolID varchar(50),--驾校ID
@TeacherID varchar(50);--教师ID
--在inserted表中查询已经插入记录信息
select @SchoolID = SchoolID,@TeacherID = TeacherID from inserted;
--获得教学总分
select @Teaching=SUM(Teaching) from t_DynamicScore where SchoolID=@SchoolID;
--环境总分
select @Environmental=SUM(Environmental) from t_DynamicScore where SchoolID=@SchoolID;
--车辆总分
select @Cars=SUM(Cars) from t_DynamicScore where SchoolID=@SchoolID;
--教练总分
SQLServer 新增数据时触发器自动计算并更新相关值
最新推荐文章于 2024-08-01 17:10:09 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)