0% found this document useful (0 votes)
48 views8 pages

Mysql Insert Into Statement

Uploaded by

salimdz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views8 pages

Mysql Insert Into Statement

Uploaded by

salimdz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

 Tutorials  Exercises  Services   Sign Up Log in

HTML
 CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C

MySQL INSERT INTO Statement


❮ Previous Next ❯

The MySQL INSERT INTO Statement


The INSERT INTO statement is used to insert new records in a table.

INSERT INTO Syntax


It is possible to write the INSERT INTO statement in two ways:

1. Specify both the column names and the values to be inserted:

INSERT INTO table_name (column1, column2, column3, ...)


VALUES (value1, value2, value3, ...);

2. If you are adding values for all the columns of the table, you do not need to specify
the column names in the SQL query. However, make sure the order of the values is in
the same order as the columns in the table. Here, the INSERT INTO syntax would be as
follows:

INSERT INTO table_name


VALUES (value1, value2, value3, ...);
 Tutorials  Exercises  Services   Sign Up Log in
Demo Database
HTML
 CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C
Below is a selection from the "Customers" table in the Northwind sample database:

CustomerID CustomerName ContactName Address City PostalCode

89 White Clover Karl Jablonski 305 - 14th Seattle 98128


Markets Ave. S.
Suite 3B

90 Wilman Kala Matti Keskuskatu Helsinki 21240


Karttunen 45

91 Wolski Zbyszek ul. Filtrowa Walla 01-012


68

INSERT INTO Example


The following SQL statement inserts a new record in the "Customers" table:

Example Get your own SQL Server

INSERT INTO Customers (CustomerName, ContactName, Address, City, PostalCode,


Country)
VALUES ('Cardinal', 'Tom B. Erichsen', 'Skagen 21', 'Stavanger', '4006',
'Norway');

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

CustomerID CustomerName ContactName Address City PostalCo


89 Tutorials  White Clover
Exercises
Markets
Karl Jablonski
Services  305
 - 14th
Ave. S.
Seattle
Sign Up 98128
Log in

HTML
 CSS JAVASCRIPT SQL PYTHON JAVASuitePHP
3B HOW TO W3.CSS C

90 Wilman Kala Matti Keskuskatu Helsinki 21240


Karttunen 45

91 Wolski Zbyszek ul. Filtrowa Walla 01-012


68

92 Cardinal Tom B. Skagen 21 Stavanger 4006


Erichsen

Did you notice that we did not insert any number into the CustomerID field?
The CustomerID column is an auto-increment field and will be generated automatically
when a new record is inserted into the table.

Insert Data Only in Specified Columns


It is also possible to only insert data in specific columns.

The following SQL statement will insert a new record, but only insert data in the
"CustomerName", "City", and "Country" columns (CustomerID will be updated
automatically):

Example

INSERT INTO Customers (CustomerName, City, Country)


VALUES ('Cardinal', 'Stavanger', 'Norway');

The selection from the "Customers" table will now look like this:
CustomerID
Tutorials  Exercises  Services 
CustomerName ContactName

Address City
Sign Up Log in
PostalCo

HTML
 CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C
89 White Clover Karl Jablonski 305 - 14th Seattle 98128
Markets Ave. S.
Suite 3B

90 Wilman Kala Matti Keskuskatu Helsinki 21240


Karttunen 45

91 Wolski Zbyszek ul. Filtrowa Walla 01-012


68

92 Cardinal null null Stavanger null

Test Yourself With Exercises

Exercise:
Insert a new record in the Customers table.

Customers
CustomerName,
Address,
City,
PostalCode,
Country

'Hekkan Burger',
'Gateveien 15',
'Sandnes',
'4306',
 'Norway'
Tutorials 
;
Exercises  Services   Sign Up Log in

HTML
 CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C

Submit Answer »

Start the Exercise

❮ Previous Log in to track progress Next ❯

COLOR PICKER


 Tutorials  Exercises  Services   Sign Up Log in

HTML
 CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C

 SPACES UPGRADE NEWSLETTER

GET CERTIFIED REPORT ERROR


Top Tutorials Top References
 Tutorials  Exercises  Services   Sign Up Log in
HTML Tutorial HTML Reference
HTML
 CSS CSS Tutorial
JAVASCRIPT SQL PYTHON CSS Reference PHP
JAVA HOW TO W3.CSS C
JavaScript Tutorial JavaScript Reference
How To Tutorial SQL Reference
SQL Tutorial Python Reference
Python Tutorial W3.CSS Reference
W3.CSS Tutorial Bootstrap Reference
Bootstrap Tutorial PHP Reference
PHP Tutorial HTML Colors
Java Tutorial Java Reference
C++ Tutorial Angular Reference
jQuery Tutorial jQuery Reference

Top Examples Get Certified


HTML Examples HTML Certificate
CSS Examples CSS Certificate
JavaScript Examples JavaScript Certificate
How To Examples Front End Certificate
SQL Examples SQL Certificate
Python Examples Python Certificate
W3.CSS Examples PHP Certificate
Bootstrap Examples jQuery Certificate
PHP Examples Java Certificate
Java Examples C++ Certificate
XML Examples C# Certificate
jQuery Examples XML Certificate

    FORUM ABOUT
W3Schools is optimized for learning and training. Examples might be simplified to
improve reading and learning.
Tutorials, references, and examples are constantly reviewed to avoid errors, but we
cannot warrant full correctness
of all content. While using W3Schools, you agree to have read and accepted our terms of
use, cookie and privacy policy.

Copyright 1999-2023 by Refsnes Data. All Rights Reserved. W3Schools is Powered by


W3.CSS.

 Tutorials  Exercises  Services   Sign Up Log in

HTML
 CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C

You might also like