SQL触发器练习题求解
发布网友
发布时间:2022-04-09 06:10
我来回答
共1个回答
热心网友
时间:2022-04-09 07:39
Create TRIGGER 成绩表_TRIG ON 成绩表 FOR INSERT , UPDATE
AS
BEGIN
SET NOCOUNT ON
Declare @InsertedCount Int
Declare @DeletedCount Int
Set @InsertedCount = (Select Count(*) From Inserted)
Set @DeletedCount = (Select Count(*) From Deleted)
If (@InsertedCount>0) Begin
UPDATE 成绩表 SET 成绩表.总评 = 成绩表.平时成绩 + 成绩表.期中成绩 + 成绩表.期末成绩 From Inserted Where 成绩表.学号=Inserted.学号
End
If (@DeletedCount>0) Begin
UPDATE 成绩表 SET 成绩表.总评 = 成绩表.平时成绩 + 成绩表.期中成绩 + 成绩表.期末成绩 From Deleted Where 成绩表.学号=deleted.学号
End
SET NOCOUNT OFF
END