日期:2014-05-18 浏览次数:20914 次
CREATE TRIGGER dbo.ck_credit ON dbo.sc AFTER INSERT AS DECLARE @tatal tinyint SELECT @tatal=sum(credit) FROM ( SELECT sno,credit FROM sc,course WHERE sc.sno=inserted.sno AND sc.sno=course.sno)t IF @tatal > 30 BEGIN ROLLBACK RAISERROR('错误提示',16,1) END GO
------解决方案--------------------
CREATE TRIGGER dbo.ck_credit
ON dbo.sc
AFTER INSERT
AS
DECLARE @tatal tinyint
SELECT @tatal=sum(credit)
FROM (
SELECT sno,credit
FROM sc,course,inserted
WHERE sc.sno=inserted.sno AND sc.sno=course.sno) A
IF @tatal > 30
BEGIN
ROLLBACK
RAISERROR('错误提示',16,1)
END
GO
------解决方案--------------------
---查询表要取别名a CREATE TRIGGER dbo.ck_credit ON dbo.sc AFTER INSERT AS DECLARE @tatal tinyint SELECT @tatal=sum(credit) FROM ( SELECT sno,credit FROM sc,course WHERE sc.sno=inserted.sno AND sc.sno=course.sno)a IF @tatal > 30 BEGIN ROLLBACK RAISERROR('错误提示',16,1) END GO
------解决方案--------------------
CREATE TRIGGER dbo.ck_credit
ON dbo.sc
AFTER INSERT
AS
--DECLARE @tatal tinyint
--SELECT @tatal=sum(credit)
IF ( SELECT sum(T.credit)
FROM (
SELECT sno,credit
FROM sc,course,inserted
WHERE sc.sno=inserted.sno AND
sc.cno=course.cno) AS T) >30
--IF @tatal > 30
BEGIN
ROLLBACK
RAISERROR('错误提示',16,1)
END
GO
------解决方案--------------------
CREATE TRIGGER dbo.ck_credit ON dbo.sc AFTER INSERT AS --DECLARE @tatal tinyint IF (SELECT sum(credit所在的表名.credit) FROM ( SELECT sno,credit FROM sc,course,inserted--少了一个表啊,我给你加上你又不看 WHERE sc.sno=inserted.sno AND sc.sno=course.sno) as T)>30 BEGIN ROLLBACK RAISERROR('错误提示',16,1) END GO