INSERT INTO Statement
Last updated
Last updated
The INSERT INTO statement is used to insert new records in a table.
It is possible to write the INSERT INTO statement in two ways.
The first way specifies both the column names and the values to be inserted:
If you are adding values for all the columns of the table, you do not need to specify the column names in the SQL query. However, make sure the order of the values is in the same order as the columns in the table. The INSERT INTO syntax would be as follows:
Below is a selection from the "Customers" table :
The following SQL statement inserts a new record in the "Customers" table:
The selection from the "Customers" table will now look like this:
Did you notice that we did not insert any number into the CustomerID field? The Customer ID column is an auto-increment field and will be generated automatically when a new record is inserted into the table.
It is also possible to only insert data in specific columns.
The following SQL statement will insert a new record, but only insert data in the "Customer Name", "City", and "Country" columns (CustomerID will be updated automatically):
The selection from the "Customers" table will now look like this: