INSERT INTO - Used to add new rows to the table.
The syntax of SQL INSERT INTO
Using the enumeration values, indicating the column:
Using the list of values, without specifying the columns:
In the latter case, the table can insert more than one record. If the table has other fields requiring fill, but not specified in the statement insert, Then for them to be installed with a default or null, if the default is not installed.
Example
Is the following table "Persons":
| P_Id | LastName | FirstName | Address | City |
|---|---|---|---|---|
| 1 | Hansen | Ola | Timoteivn 10 | Sandnes |
| 2 | Svendson | Tove | Borgvn 23 | Sandnes |
| 3 | Pettersen | Kari | Storgt 20 | Stavanger |
Now we add a new row in the table "Persons".
Using the following SQL query:
Now the table "Persons" has the following form:
| P_Id | LastName | FirstName | Address | City |
|---|---|---|---|---|
| 1 | Hansen | Ola | Timoteivn 10 | Sandnes |
| 2 | Svendson | Tove | Borgvn 23 | Sandnes |
| 3 | Pettersen | Kari | Storgt 20 | Stavanger |
| 4 | Nilsen | Johan | Bakken 2 | Stavanger |
Inserting the data only in a special column
SQL provides the ability to insert data into the needed columns.
The following SQL query to add a new row, but the data will be contained only in the columns "P_Id", "LastName" и "FirstName":
Now the table "Persons" has the following form:
| P_Id | LastName | FirstName | Address | City |
|---|---|---|---|---|
| 1 | Hansen | Ola | Timoteivn 10 | Sandnes |
| 2 | Svendson | Tove | Borgvn 23 | Sandnes |
| 3 | Pettersen | Kari | Storgt 20 | Stavanger |
| 4 | Nilsen | Johan | Bakken 2 | Stavanger |
| 5 | Tjessem | Jakob |
Introduction to SQL

