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 (
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.