SQL INSERT INTO Statement

Friday, October 28, 2011

tags SQL

The INSERT INTO statement is used to insert a new row in a table. The INSERT INTO statement can be written in many forms to insert data into a table. If the statement does not specify the order of the columns,   the values are added beginning with the first column.  Alternatetively, the columns could be specified, in any order, some or all.

SQL INSERT INTO Syntax

INSERT INTO table_name
VALUES (value1, value2, value3,...)


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

SQL INSERT INTO Examples

INSERT INTO Customers
VALUES (1015,'Smith', 'John', 'Georgia', 'Atlanta')

INSERT INTO Customers (CustId, LastName, FirstName)
VALUES (1015, 'Smith', 'John')

INSERT INTO also allows multiple rows to be inserted at one time. Unlike the previous example, where a single row of data was inserted into the table, we can also use the SELECT statement to specify the data that we want to insert into the table, from another table.


INSERT INTO StoreData (storeName,Date,CustID)
SELECT storeName, Date, CustID
FROM AllSales

Please help us spread the word by socializing it today!

email contact us

Did you find something wrong with the information on this page? Please take a moment to report it to us so that we can continue to improve the quality of the information on this site. Click here to report an issue with this page.



Recommended Books & Training Resources

Head First SQL: Your Brain on SQL A Learners Guide SQL Cookbook