WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

SQL INSERT INTO


The INSERT INTO statement is used to add new rows of data to a table in the database.


The SQL INSERT INTO Statement

The INSERT INTO statement is used to add new rows of data to a table in the database.

SQL INSERT INTO Syntax

It is possible to write the INSERT INTO statement in two forms.

The SQL INSERT INTO syntax is as follows:

INSERT INTO table_name1
VALUES (value1,value2,value3,...);

The second SQL INSERT INTO syntax is as follows:

INSERT INTO table_name2 (column1,column2,column3,...)
VALUES (value1,value2,value3,...);

Database

In this tutorial we will use the sample database.

Below is a selection from the "Customers" table:

CustomerID FirstName City Country
1 Jhon Dallas United States
2 Eva Houston United States
3 Maria Texas USA
4

Rajesh Delhi India
5

Stephine Lule UK

INSERT INTO Example

Assume we wish to insert a new row in the "Customers" table.

We can use the following SQL statement:

Example

INSERT INTO Customers (CustomerID,FirstName,City,Country )
VALUES ('1','Tony','Delhi','India');


The selection from the "Customers" table will now look like this:

CustomerID FirstName Place Phonenumber City
1 Robert L. Gardner Briarhill Lane Youngstown 704-376-9376 OH
2 Anna W. Simpson Kooter Lane Charlotte +108737-363 NC
3 Sally E. Davison Burnside Court Phoenix +1602-447-7098 AZ
3

Bethany G. Gibbs Brooke Street Houston +1713-621-1441 TX
4

Charles A. Arias Carter Street St Libory +1618-768-6686 IL
5 Billy D. Perry Middleville Road Santa Fe Springs +626-399-3811 CA

Insert Data in Specified Columns

It is used to insert the data into the corresponding columns:.

The following SQL statement will insert a new row, but only insert data in the "CustomerName", "Company", and "Favorite color" columns :

Example

INSERT INTO Customers (CustomerName, Company, )
VALUES ('Raymond M. Keating', 'Netobill', 'Orange');

The selection from the "Customers" table will now look like this:

CustomerID FirstName Birthday Company Occupation Favorite color
1 September 8, 1942 Netobill Counter and rental clerk Orange
2 Gary C. Grace September 27, 1962 Honest Air Group Trial lawyer Blue
3 Heather N. McAnults January 9, 1960 Zephyr Investments Climatologist Blue
4

Armand E. Reese August 8, 1997 Nutri G Abdominal sonographer Blue
5

Kristina H. Riveria August 1, 1938 Kent's Allopathic surgeon Green