学生表、课程表,学生课程关系表中怎么修改学生id信息

来源:百度知道 编辑:UC知道 时间:2024/06/23 08:27:45
例如,学生表(student)中,包含学生姓名(sname)等基本信息主键列学号(StuId),课程表(course)包含课程名称(cname)等基本信息主键(cid),学生课程关系表(card)只有3个字段,stuId,cid和score(成绩),其中stuid,cid都是引用学生和课程表中的主键。问题1,将‘物理’成绩为‘100’分并且姓名为‘张三’的学号该为‘1’。问题2,删除英语成绩小于60分的学生信息。要求,用sql语句写。

问题1:原学生表中没有学号是1的??,如果没有可以改
update student set Stuid=1 where Stuid=(select stuid from card where score=100 and cid=(select cid from course where cmane='物理')) and sname='张三'

这个表改后card 表里相应的张三的数据就与student表里不相符了.

delete from student where Stuid in (select stuid from card where score<60 and cid=(select cid from course where cname='英语'))
同样的删除数据后,找不到对应的student表里的

这种结构的表之间应该还有外键关联

像你这么改要乱套的

1、
update a set a.StuId='1' from student a inner join card b on a.StuId=b.stuId inner join course c on b.cid=c.cid where c.cname='物理' and b.score=100 and a.sname='张三’
2、
delete from student a inner join card b on a.StuId=b.stuId inner join course c on b.cid=c.cid where c.cname='英语' and b.score<60

以上,希望对你有所帮助

1
update student set s.StuId='1' from student s inner join course co on s.StuId=co.stuid inner join card ca on co.cid=ca.cid where