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

Instruction

Okay, let's get started! Previously in this course, we talked about how you can insert data into a table by providing values for only some of the columns.

For example, suppose the teacher would like to insert the date (November 10, 2018) of a written and an oral history exam for the student Tom Muller, Id = 11. This is not all the data that could be inserted into the table (we could insert the date of the oral exam, for example). Let's see how to write this query:

INSERT INTO Exam (Id, StudentId, Subject, WrittenExamDate, OralExamScore) 
VALUES (16, 11, N'History', '2018-11-10', 20); 

After the table name (Exam), only some of the column names (Id, StudentId, Subject, WrittenExamDate, OralExamScore) are listed. Likewise, only the values for those columns are given.

Recall that the database inserts NULLs into each column you omit in an INSERT statement. If you have several columns with NULLs, it is convenient to omit them.

Warning: Sometimes, the database will not allow you to add incomplete data. This topic is beyond the scope of this course.

Exercise

Add a new student with Id = 11 to the Student table. The teacher knows only his last name: Barry.
Don't use NULL when inserting this data.