Subsections

1.4.12.3 The INSERT INTO Statement

The INSERT INTO statement is used to insert new rows into a table.

Syntax

INSERT INTO table_name (column1, column2,...) VALUES (value1, value2,....)

1.4.12.3.1 Insert a New Row

This Person table:

+----------+-----------+--------+-------------+
| LastName | FirstName | Number | DateOfBirth |
+----------+-----------+--------+-------------+
| 'Smith'  | 'John'    | 10     | 1980-01-01  |
| 'Doe'    | 'John'    | 3      | 1981-12-25  |
+----------+-----------+--------+-------------+

And this SQL statement:

INSERT INTO Person (LastName, FirstName, Number, DateOfBirth)
VALUES ('Blair', 'Tony', 8, '1953-05-06')

Note: web.database expects the SQL to all be on one line. The line break here is for formatting

Will give this result:

+----------+-----------+--------+-------------+
| LastName | FirstName | Number | DateOfBirth |
+----------+-----------+--------+-------------+
| 'Smith'  | 'John'    | 10     | 1980-01-01  |
| 'Doe'    | 'John'    | 3      | 1981-12-25  |
| 'Blair'  | 'Tony'    | 8      | 1953-05-06  |
+----------+-----------+--------+-------------+

If you are extremely careful, the column names can be omitted as long as the values are specified in the same order as the columns when the table was created.

The SQL below would achieve the same result as the previous SQL statement:

INSERT INTO Person VALUES ('Blair', 'Tony', 8, '1953-05-06')

Warning: It is very easy to make a mistake with the shortened syntax so it is recommended you use the full version and specify the column names.