update Score set Score.StudentID=

解决方案 »

  1.   

    先把sql语句调通了,再写后台
      

  2.   

    程序没报什么错,就是不能实现更新操作
    我就是找到Student表里的CourseID与Score表的CourseID一样的记录,再将该记录的StudentID字段更新成与Student表一样的值(在Score表里原先StudentID是空的)
      

  3.   

    程序没报什么错,就是不能实现更新操作
    我就是找到Student表里的CourseID与Score表的CourseID一样的记录,再将该记录的StudentID字段更新成与Student表一样的值(在Score表里原先StudentID是空的)
    看一下update的语法,你再看看红色部分,这个sql编译应该通不过的。
    update Score(StudentID)set StudentID=Student.StudentID where CourseID=(select CourseID1 from Student)or CourseID=(select CourseID2 from Student)你要的效果用下面的语句
    update Score set StudentID=Student.StudentID from Score,Student where 
    Score.CourseID = Student.CourseID1 or Score.CourseID = Student.CourseID2还有一点我很好奇,在Student表里会不会出现相同的CourseID1或CourseID2。
    比如数据如下。这样Score表的ID更新成001,还是002?
    Student表
    StudentID CourseID1 CourseID2
    001       语文      数学
    002       语文      物理Score表
    StudentID CourseID
              语文
     
      

  4.   

    UPDATE 表名  SET 更新的字段 = 更新的值 WHERE 更新条件
      

  5.   

    程序没报什么错,就是不能实现更新操作
    我就是找到Student表里的CourseID与Score表的CourseID一样的记录,再将该记录的StudentID字段更新成与Student表一样的值(在Score表里原先StudentID是空的)
    看一下update的语法,你再看看红色部分,这个sql编译应该通不过的。
    update Score(StudentID)set StudentID=Student.StudentID where CourseID=(select CourseID1 from Student)or CourseID=(select CourseID2 from Student)你要的效果用下面的语句
    update Score set StudentID=Student.StudentID from Score,Student where 
    Score.CourseID = Student.CourseID1 or Score.CourseID = Student.CourseID2还有一点我很好奇,在Student表里会不会出现相同的CourseID1或CourseID2。
    比如数据如下。这样Score表的ID更新成001,还是002?
    Student表
    StudentID CourseID1 CourseID2
    001       语文      数学
    002       语文      物理Score表
    StudentID CourseID
              语文
     

    发帖后我知道update语法错了,后来我把Update语句改成
    update Score set Score.StudentID=Student.StudentID where CourseID=(select CourseID1 from Student)or CourseID=(select CourseID2 from Student)Student表有CourseID1和CourseID2的意思是,一个学生可以选修两门课程,但是Teacher表里只有一个CourseID,就是一位老师只能交一门课程。我现在就是要把老师选教的课插入到Score,再将选了同样的课的学生ID更新到这条记录的StudentID字段里。这样老师就能给对应的学生打分了
      

  6.   

    我很遗憾的告诉你,你只改update是不行的,在Student.StudentID这里还是编译不过,实在不行你在SQL Server Management Studio里面运行一下就知道了。
    你的思路有问题,你先把Teacher表中的CourseID更新到Score,然后再想办法,更新StudentID,但是你忘了同一门课程可能有多个人选修。
    其实你直接从Student获取数据插入Score表就行了。
    insert Score(StudentID,CourseID) 
    select StudentID, CourseID1 as CourseID from Student where CourseID1 is not null and CourseID1 != ''
    union select StudentID, CourseID2 as CourseID from Student where CourseID2 is not null and CourseID2 != ''
      

  7.   

    我很遗憾的告诉你,你只改update是不行的,在Student.StudentID这里还是编译不过,实在不行你在SQL Server Management Studio里面运行一下就知道了。
    你的思路有问题,你先把Teacher表中的CourseID更新到Score,然后再想办法,更新StudentID,但是你忘了同一门课程可能有多个人选修。
    其实你直接从Student获取数据插入Score表就行了。
    insert Score(StudentID,CourseID) 
    select StudentID, CourseID1 as CourseID from Student where CourseID1 is not null and CourseID1 != ''
    union select StudentID, CourseID2 as CourseID from Student where CourseID2 is not null and CourseID2 != ''
    我现在有点混乱了,我也觉得我的思路有点问题了
    那我想请教您一个问题,就是要建一个学生分数查询系统,数据库里最基本要建多少个表,分别是做什么的?