1.为表student_course创建一个更新触发器,当更改表的成绩数据时,如果成绩由原来的小于60分更改为大于等于60分,该学生就能得到相应的学分,如果成绩由原来的大于等于60分更改为小于60分,该学生就能相应的学分为0。2.为表student创建一个更新触发器,当更改表中某学号学生的姓名时,同时将student_course中该学生的姓名更新。
这两道题怎么做啊~

解决方案 »

  1.   

    1.为表student_course创建一个更新触发器,当更改表的成绩数据时,如果成绩由原来的小于60分更改为大于等于60分,该学生就能得到相应的学分,如果成绩由原来的大于等于60分更改为小于60分,该学生就能相应的学分为0。create trigger my_trig on student_course for update
    as
    begin
      declare @score1 as int
      declare @score2 as int
      select @score1 = score from deleted
      select @score2 = score from inserted
      if @score2 >= 60 and @score1 < 60 
         update tb set xf = 相应的学分 where id = (select id from inserted)
      if @score2 < 60 and @score1 >= 60 
         update tb set xf = 0 where id = (select id from inserted)
    end
      

  2.   

    2.为表student创建一个更新触发器,当更改表中某学号学生的姓名时,同时将student_course中该学生的姓名更新。
    create trigger my_trig on student for update
    as
    begin
      update student_course
      set name = i.name 
      from student_course t , inserted i
      where t.id = i.id
    end
      

  3.   

    2.为表student创建一个更新触发器,当更改表中某学号学生的姓名时,同时将student_course中该学生的姓名更新。
    create tigger f on student
    for update
    as
    begin
    update a set a.姓名=i.姓名 from student_course a, inserted i where a.学号=i.学号 and i.学号=xx
    end
      

  4.   

    写错了,应该是studentcreate trigger my_trig on student_course for update
    as
    begin
      declare @score1 as int
      declare @score2 as int
      select @score1 = score from deleted
      select @score2 = score from inserted
      if @score2 >= 60 and @score1 < 60 
         update student_course set xf = 相应的学分 where id = (select id from inserted)
      if @score2 < 60 and @score1 >= 60 
         update student_course set xf = 0 where id = (select id from inserted)
    end
      

  5.   

    这样写对吗?create trigger z on student_course
    for update
    as
    begin
      declare @x  int
      declare @y  int
      select @x = grade from deleted
      select @y = grade from inserted
      if @y >= 60 and @x < 60 
         update student_course set student_course.credit = student_course.credit where course_id = (select course_id from inserted)
      if @y < 60 and @x >= 60 
         update student_course set student_course.credit = 0 where course_id = (select course_id from inserted)
    end
      

  6.   

    student_course表里边有grade(成绩)、credit(学分) 这两列
    courese表里边有credit(学分)
      

  7.   

    请问CSDN管理员及各位C友!为什么CSDN需要我没完没了的登录?只要我点击了通知,私信,好友,然后我每回复一帖系统就要我登录一次,从6.1到今天,至少已经登录了数百次了.
    (前些日子情况稍好些.)实在忍无可忍,只好发帖了质问了.环境: windows2003 + IE6请问:是我系统(设置)的问题,还是CSDN开发人员水平太烂,居然烂到如此地步?另外:发此帖登录三次,内容重写两遍(因为发贴后又要我登录,然后写的内容就无踪影了,只好重写).在此对CSDN这种机制发表自己强烈的愤怒和进行强烈的抗议!如有类似经历者,请指点我该如何操作,谢谢.最后,我居然发不出帖!!!请小F或roy_888帮我发出此帖,谢谢!
      

  8.   

    谁帮我解决第一道题啊。。
    student_course表里边有grade(成绩)、credit(学分) 这两列
    courese表里边有credit(学分)
      

  9.   

    create trigger z on student_course
    for update
    as
    begin
      declare @x int
      declare @y int
      select @x = grade from deleted
      select @y = grade from inserted
      if @y >= 60 and @x < 60  
      update student_course set credit = n.credit 
      from student_course m, courese n, inserted i
      where m.course_id = n.courese and m.courese_id = i.courese_id  --我怎么觉得你应该有个学号才对。例如ID
      update student_course set credit = n.credit 
      from student_course m, courese n, inserted i
      where m.course_id = n.courese and m.id = i.id  if @y < 60 and @x >= 60  
      update student_course set student_course.credit = 0 where course_id = (select course_id from inserted)
    end请问CSDN管理员及各位C友!为什么CSDN需要我没完没了的登录?只要我点击了通知,私信,好友,然后我每回复一帖系统就要我登录一次,从6.1到今天,至少已经登录了数百次了.
    (前些日子情况稍好些.)实在忍无可忍,只好发帖了质问了.环境: windows2003 + IE6请问:是我系统(设置)的问题,还是CSDN开发人员水平太烂,居然烂到如此地步?另外:发此帖登录三次,内容重写两遍(因为发贴后又要我登录,然后写的内容就无踪影了,只好重写).在此对CSDN这种机制发表自己强烈的愤怒和进行强烈的抗议!如有类似经历者,请指点我该如何操作,谢谢.最后,我居然发不出帖!!!请小F或roy_88帮我发出此帖,谢谢!又发现一个问题,如果连续这样回帖,在一分钟内不需要登录,超过了又需要登录了。
      

  10.   

    呵呵 你会不会写错了?
    上面定义的是courese n
    然后你用n.courese ?
      

  11.   

    update student_course set credit = n.credit 
    from student_course m, courese n, inserted i
    where m.course_id = n.course_id and m.courese_id = i.courese_id