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:
 INSERT INTO table
   VALUES ( value1, value2, .... )

 INSERT INTO table ( col1, col2, col3, ... )
   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:

 INSERT INTO  Persons
   VALUES( 1, 'Hansen', 'Ola', 'Timoteivn 10', 'Sandnes' );
 INSERT INTO  Persons
   VALUES( 2, 'Svendson', 'Tove', 'Borgvn 23', 'Sandnes' );
 INSERT INTO  Persons
   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
Below is an SQL test area from W3Schools, which uses the well-known Northwind sample database. The tables here are for read only because of the problem of embedding the scripts. For a fully working example, check this by using Chrome.

SQL Statement:

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

Result:
The Database includes:
The Database includes:

TablenameRecord
Customers91
Categories8
Employees10
OrderDetails518
Orders196
Products77
Shippers3
Suppliers29




      “There are moments when troubles enter our lives and we can do nothing to avoid them.    
      But they are there for a reason.    
      Only when we have overcome them will we understand why they were there.”    
      ― Paulo Coelho, The Fifth Mountain