I have the following problem:
I am trying to add every student in the Comp. Sci. department into a course, here are the DDL for the relations:
The desired course has values of (‘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
The problem is that I’m getting an error when trying to use an update statement (Error is 1241 Operand should have 1 column), correct my syntax as it is more than likely the problem:
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.'
);
Sorry I’m new at MySQL, if you could just guide me to correcting my syntax and possibly a better solution than mine (not sure if mine is even a solution).
You have not specified a column in you
WHEREclause that’s is why you are gettingError 1241 Operand should contain 1 column(s)Alternatively, join both tables