Slide 7.5: SQL create table statement
Slide 7.7: SQL insert into statement (cont.)
Home

SQL Insert into Statement


The INSERT INTO statement is used to insert new rows into a table. It is possible to write the insert into statement in two forms:
1INSERT INTO table
2  VALUES ( value1, value2, .... )

1INSERT INTO table ( col1, col2, col3, ... )
2  VALUES ( value1, value2, .... )
The following empty table Persons was created by the previous create table statement:

P_Id LastName FirstName Address City
         

Insert three persons into the table Persons:

1INSERT INTO  Persons
2  VALUES (1, 'Hansen', 'Ola', 'Timoteivn 10', 'Sandnes');
3INSERT INTO  Persons
4  VALUES (2, 'Svendson', 'Tove', 'Borgvn 23', 'Sandnes');
5INSERT INTO  Persons
6  VALUES (3, 'Pettersen', 'Kari', 'Storgt 20', 'Stavanger');

The table Persons now becomes the following:

P_Id LastName FirstName Address City
1 Hansen Ola Timoteivn 10 Sandnes
2 Svendson Tove Borgvn 23 Sandnes
3 Pettersen Kari Storgt 20 Stavanger


Demonstration
The following is an SQL test area from W3Schools, which uses the well-known Northwind sample database and the tables are for read only.
For security reasons, the following demonstration may only work in Chrome.

SQL Statement:

Edit the SQL statement and click     to see the result, or    

Result:

Click “Run SQL” to execute the SQL statement above.
W3Schools has created an SQL database in your browser.
The menu to the right displays the database, and will reflect any changes.
Feel free to experiment with any SQL statement.
You can restore the database at any time.
The Database includes:
The Database includes:

TablenamesRecords
Customers91
Categories8
Employees10
OrderDetails518
Orders196
Products77
Shippers3
Suppliers29