日期:2014-05-18  浏览次数:20581 次

简单触发器问题。求大神
创建一触发器,当修改课程编号时,成绩表中的课程编号也要做相应修改。
score course 主键cno


------解决方案--------------------
SQL code

CREATE table score
(cno varchar(10))

CREATE table course
(cno varchar(10))

INSERT INTO score SELECT '001'
INSERT INTO course SELECT '001'

CREATE TRIGGER tr_Update ON course FOR UPDATE 
AS
BEGIN
    declare @DeleteCno int
    declare @InsertCno int
    select @DeleteCno=cno from deleted
    select @InsertCno=cno from inserted
    update score set cno=@InsertCno where cno=@DeleteCno
END

UPDATE course SET cno ='002' WHERE cno='001'