Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Introduction
Inserting and updating NULLs
6. UPDATE with NULL in SET
Conditions in UPDATE and DELETE
Using values from another column
Return rows in INSERT, UPDATE, DELETE
Summary

Instruction

Fantastic! You already know how to insert data with NULLs. You can also use NULL in UPDATE statements.

Suppose the teacher made a mistake. Tom Muller wrote the written exam but the teacher hasn't checked this exam (exam ID of 17). Nevertheless, Tom has the score of the written exam (WrittenExamScore) and the date (WrittenScoreDate), but he shouldn't. In this case, the only known value is the actual date of the written exam. The other two values you must move. How would you do this?

It's simple! Look at the command below:

UPDATE Exam 
SET WrittenExamScore = NULL, WrittenScoreDate = NULL
WHERE Id = 17;

After SET, we used two comma-separated column names to update WrittenExamScore and WrittenScoreDate. Each column was assigned NULL. In the WHERE condition, we update only the exam with Id = 17. In this way, we correct our mistake.

Exercise

In the database, the teacher stores the student name Laura Donna Ross (Id = 10). However, Laura doesn't have a middle name; Donna is a mistake. Correct this mistake by updating the data.