Inserting Data

In the Selecting Data article we assumed that we already have some data in our Countries table, but how did we populate this table? Inserting data into a table is done with the INSERT SQL keyword. If we have the Countries table, which is empty, we would insert 1 row with the following SQL statement:

(Country, Continent, Capital, Population)
VALUES (‘USA’, ‘North America’, ‘Washington’, 298444215)

We would insert the rest of our data in the same manner.

The INSERT INTO clause is followed by the name of the table in which we insert data. Then we have a comma-separated list of column names within parenthesis then we have the SQL keyword VALUES followed by a comma-separated list of values, again in parenthesis. As you can see the values for the first 3 columns in the Countries table are all enclosed with single quotes, and the fourth column is simply an integer number without quotes. All string values in SQL are enclosed in single quotes (if you enclose them in double quotes you will get an error), while numeric values are not.

You can put the list of columns in any order you want, but you have to match this order in the list of values, otherwise your data will be misplaced or you can get an error from your insert statement.