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

Instruction

Amazing! Let's summarize what we've learned.

We can:

  • Insert data using NULLs for unknown values in a row:
    INSERT INTO Student 
    VALUES (21, N'Tom', NULL, N'Muller');
    
  • Change values using NULL and UPDATE:
    UPDATE Exam 
    SET WrittenExamScore = NULL
    WHERE Id = 5;
    
  • Change a value in a column or delete a row if the column contains a NULL:
    UPDATE Student
    SET LastName = N'unknown' 
    WHERE LastName IS NULL;
    
    DELETE FROM Student 
    WHERE LastName IS NULL;
  • Update or delete using AND and OR to meet certain conditions:
    DELETE FROM Exam 
    WHERE Subject = N'Spanish' 
    AND (WrittenScoreExam IS NULL OR OralScoreExam IS NULL)
  • List columns with the Inserted or Deleted prefixes:
    UPDATE Student
    OUTPUT Inserted.FirstName, Inserted.LastName,
    Deleted.FirstName, Deleted.LastName
    SET FirstName = N'Alan', LastName = N'Stanley'
    WHERE Id = 12;
    

Exercise

Click Next exercise to finish this part.