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 history exam for the student Tom Muller, id = 11
, and the score of his oral history exam. 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, student_id, subject, written_exam_date, oral_exam_score)
VALUES (16, 11, 'History', '2018-11-10', 20);
After the table name (exam
), only some of the column names (id
, student_id
, subject
, written_exam_date
, oral_exam_score
) are listed. Likewise, only the values for those columns are given.
Recall that the database inserts NULL
s into each column you omit in an INSERT
statement. If you have several columns with NULL
s, 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—you can learn about it in our Creating Tables in SQL course.