Deprecated: mysql_query(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /home/sqldump/public_html/config.php on line 184

Warning: mysql_query(): Access denied for user ''@'localhost' (using password: NO) in /home/sqldump/public_html/config.php on line 184

Warning: mysql_query(): A link to the server could not be established in /home/sqldump/public_html/config.php on line 184
SQL INSERT tutorial and database insert query examples

SQL statement: INSERT

There are two ways to insert data into an SQL table using the INSERT command. The first of which doesn't specify any column names but the order you specify the values is important and requires a value for each field. This command inserts a customer into the Customers table.

INSERT INTO Customers VALUES ('Joe','Bloggs','joe@example.com','0123 456 567','Canada')

However, if you are not inserting a complete row. For example, if you would just like to insert the customers name, you could simply run the following:

INSERT INTO Customers (FirstName, LastName) VALUES ('Joe','Bloggs')

Alternatively, you can also insert data into an SQL database by running the following command:

INSERT INTO Customers SET FirstName = 'Joe', LastName = 'Bloggs'

Running ALL of the above commands will leave our table looking like this:

FirstName LastName EmailAddress TelephoneNumber Country
John Doe john.doe@example.com 01234 234 234 United Kingdom
Arnold Schwarzenegger arnie.schwarzenegger@example.com 69872 726 732 Austria
Sylvester Stallone sylv.stallone@example.com 888 123 456 United States
Mike Foo mike.foo@example.com 555 893 0923 United States
Joe Bloggs joe@example.com 0123 456 567 Canada
Joe Bloggs      
Joe Bloggs      
Back to table of contents