Inserting data
2. Insert partial data

Instruction

You learn quickly, great!

Sometimes you don't know all the data when you insert information to a database. SQL allows you to insert data with values for some columns and omit data for other columns at the same time.

To insert Chris of unknown age as a user with id 6, use the command:

INSERT INTO user (id, name) VALUES (6, 'Chris'); 

The new part after the table name, (id, name), is the list of column names you will give value to. The expression (6, 'Chris'), in turn, is the list of values for these columns. The number 6 is the value of the first specified column, id. The text 'Chris' is the value of the second specified column, name. The value for unknown in SQL is NULL. A database inserts NULL values for each columns you omit in an INSERT statement.

Warning: sometimes the database will not allow you to add incomplete data. This topic is beyond the scope of this course. We'll talk about it in the Creating Tables in SQL course.

Exercise

Balkan cuisine is getting popular, so we need another Balkan item on the menu.

Add Kosovo Bread with id 10, it's a starter. We have yet to decide on the price, so omit it for now.

Stuck? Here's a hint!

Type

INSERT INTO dish (id, type, name) 
VALUES (10, 'starter', 'Kosovo Bread');