Spring Deals - hours only!Up to 70% off on all courses and bundles.-Close
Introduction
Inserting and updating NULLs
Conditions in UPDATE and DELETE
Using values from another column
12. Change values between columns
Return rows in INSERT, UPDATE, DELETE
Summary

Instruction

Oops… the English teacher just realized that she accidentally switched WrittenExamScores and OralExamScores. The last UPDATE introduced another mistake to the Exam table, again with all records for English exams. The values of the WrittenExamScore column got swapped with those of the OralExamScore column. How can we correct this? Look at the query below:

UPDATE Exam
SET WrittenExamScore = OralExamScore,
OralExamScore = WrittenExamScore
WHERE Subject = N'English'

We set new values for two columns: WrittenExamScore and OralExamScore. The first column took the value from OralExamScore, and the second column took the value from WrittenExamScore. T-SQL makes this operation easy.

Exercise

It's time to fix another mistake in our database. Somebody mistook the first name of the student whose ID is 6 for his last name. See if you can use the example query to correct this.