如何把两个触发器根据字段不同执行不同的updade语句 100
whereAutoID=@AutoIDandcInvCodein(selectcInvCodefromInventorywherecInvCCode='0101')根据0...
where AutoID=@AutoID and cInvCode in (select cInvCode from Inventory where cInvCCode='0101')
根据0101对应的字段可能是0102
原本0101跟0102是两个触发器,但是都启用后会有冲突,所以需要合并成一个 展开
根据0101对应的字段可能是0102
原本0101跟0102是两个触发器,但是都启用后会有冲突,所以需要合并成一个 展开
1个回答
展开全部
以下是SQL SERVER 编写,经测试,可以运行无误
CREATE TABLE CourseClass( --创建表CourseClass
CourseClassID int,
CourseID int,
CommonPart float(3),
MiddlePart float(3),
LastPart float(3))
GO
CREATE TABLE Grade( --创建表Grade
CourseClassID int,
CommonScore float(2),
MiddleScore float(2),
LastScore float(2),
TotalScore float(2))
GO
CREATE TRIGGER CalculateTotalScore --创建触发器CalculateTotalScore,在Grade表中更新,插入数据是自动计算出TotalScore的值并且插入到该列中
on Grade
for insert,update
as
update Grade
set TotalScore=CommonPart*CommonScore+MiddlePart*MiddleScore+LastPart*LastScore
from Grade,CourseClass where CourseClass.CourseClassID=Grade.CourseClassID
以下为测试语句
insert into CourseClass values(1,1,2,3,4)
insert into Grade values(1,20,30,40,0)
select * from CourseClass,Grade
update Grade set MiddleScore=60
select * from CourseClass,Grade
CREATE TABLE CourseClass( --创建表CourseClass
CourseClassID int,
CourseID int,
CommonPart float(3),
MiddlePart float(3),
LastPart float(3))
GO
CREATE TABLE Grade( --创建表Grade
CourseClassID int,
CommonScore float(2),
MiddleScore float(2),
LastScore float(2),
TotalScore float(2))
GO
CREATE TRIGGER CalculateTotalScore --创建触发器CalculateTotalScore,在Grade表中更新,插入数据是自动计算出TotalScore的值并且插入到该列中
on Grade
for insert,update
as
update Grade
set TotalScore=CommonPart*CommonScore+MiddlePart*MiddleScore+LastPart*LastScore
from Grade,CourseClass where CourseClass.CourseClassID=Grade.CourseClassID
以下为测试语句
insert into CourseClass values(1,1,2,3,4)
insert into Grade values(1,20,30,40,0)
select * from CourseClass,Grade
update Grade set MiddleScore=60
select * from CourseClass,Grade
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询