我有以下问题:
我正在尝试在 Comp 中添加每个学生。科学。部门进入课程,这里是关系的DDL:
所需课程的值为 ('CS-001', 'Weekly Seminar', 'Comp. Sci.', 0)
Department
(dept_name [primary key], building, budget)
Course
(course_id [primary key], title, dept_name, credits)
Instructor
(ID [primary key], name, dept_name, salary)
Foreign Key is dept_name references Department
Section
(course_id [primary key], sec_id [primary key], semester [primary key], year [primary key], building, room_number, time_slot_id)
Foreign Key course_id references Course
Teaches
( ID [primary key], course_id [primary key], sec_id [primary key], semester [primary key], year [primary key])
Foreign key ID references Instructor,
Foreign Key (course_id,sec_id,semester,year) references Section
Takes
(ID [primary key], course_id [primary key], sec_id [primary key], semester [primary key], year [primary key], grade)
Foreign key(course_id,sec_id,semester,year) references section Foreign key(ID) references student
Student
(ID [primary key], name, dept_name, tot_cred) Foreign key(dept_name) references department
问题是我在尝试使用更新语句时遇到错误(错误是1241 Operand should have 1 column
),请更正我的语法,因为它很可能是问题所在:
update takes
set ID=ID, course_id='CS-001', sec_id='1', semester='Fall', year=2009, grade=null
where
(
select distinct name, ID
from student natural join takes
where dept_name='Comp. Sci.'
);
对不起,我是 MySQL 的新手,如果你能指导我纠正我的语法,并且可能是比我的更好的解决方案(不确定我的解决方案是否是一个解决方案)。