为甚么,我对学生进行删除操作时,其他表中的信息被删掉了,偏偏StudentInformation中的删不到,请高手解答一下
CREATE TRIGGER Delete_Student  ---------删除一个学生信息,同时删除,StudentCourse,FamilyInformation,Evaluation中含所删StudentID的行
ON StudentInformation----学生信息表
INSTEAD OF DELETE
AS
DELETE f FROM FamilyInformation f,Deleted d
WHERE f.StudentID=d.StudentID
DELETE s FROM StudentCourse s,Deleted d
WHERE s.StudentID=d.StudentID 
DELETE e FROM Evaluation e,Deleted d
WHERE e.StudentID=d.StudentID 

解决方案 »

  1.   

    --TRY
    CREATE TRIGGER Delete_Student  ---------删除一个学生信息,同时删除,StudentCourse,FamilyInformation,Evaluation中含所删StudentID的行
    ON StudentInformation----学生信息表
    FOR DELETE
    AS
    DELETE f FROM FamilyInformation f,Deleted d
    WHERE f.StudentID=d.StudentID
    DELETE s FROM StudentCourse s,Deleted d
    WHERE s.StudentID=d.StudentID 
    DELETE e FROM Evaluation e,Deleted d
    WHERE e.StudentID=d.StudentID 
      

  2.   

    FamilyInformation有外键? 
    调一下顺序,把外键所在表的数据先删除试试
      

  3.   

    TO 1楼:StudentCourse,FamilyInformation,Evaluation都包含外键,为StudentInformation中的StudentID,
             所以要想删StudentInformation中的某一行,必须将StudentCourse,FamilyInformation,Evaluation中对应的行删掉,
             否则会出现异常,所以不能用For
    To 2楼:我就是这样做的,但是偏偏删不到,是不是还要再在最后添加一句删除StudentInformation的SQL语句
      

  4.   

    替代触发只执行SQL语句吧!!最后加一条吧