Information Technology IT – 10 Database and file concepts | e-Consult
10 Database and file concepts (1 questions)
Login to see all questions.
Click on a question to view the answer
Question 3 Answer:
1. Create the students table:
CREATE TABLE students (
student_id INT PRIMARY KEY,
student_name VARCHAR(255),
course_id INT,
grade VARCHAR(2)
);
2. Update the course a student is enrolled in:
UPDATE students
SET course_id = 456
WHERE student_id = 789;
3. Delete a student from the students table if they are no longer enrolled in any courses:
This requires a more complex query involving a subquery to identify students not in the courses table. Here's an example:
DELETE FROM students
WHERE studentid IN (SELECT studentid FROM students WHERE studentid NOT IN (SELECT studentid FROM courses));