w3resource logo
SQL Tutorial

SQL INSERT INTO STATEMENT

Description

The SQL INSERT statement is used to insert a single record or multiple records into a table.

While inserting a row, if the columns are not specified, it means that vales are added for all of the columns of the table resulting addition of a single row. If it is required to insert values for one or more specific column(s), then it is necessary to specify the name(s) of the column(s) in the SQL query.

The SQL SELECT statement can also be used to insert the rows of one table into another identical table.

While inserting the values, it is needed to enclose the values with single quotes for character or date values.

Syntax:

INSERT INTO < table name > (col1,col2,col3...col n)
VALUES (value1,value2,value3…value n);

Parameters:

Name Description
table_name Name of the table where data will be inserted.
col1,col2,col3,con n Column of the table.
value1,value2,value3,value n Values against each column.

You can use another syntax to insert data. Here, you don't specify column names of the associated table. So, value1 is inserted into the first column of a table, value2 into column2 and so on.

Syntax:

INSERT INTO < table name >
VALUES (value1,value2,value3…value n);

Parameters:

Name Description
table_name Name of the table where data will be inserted.
value1,value2,value3,value n Values against each column.

Example:

Sample table: agents


To add values'A001','Jodi','London','.12','075-1248798' for a single row into the table 'agents', the following SQL statement can be used :

INSERT INTO agents
VALUES ("A001","Jodi","London",.12,"075-1248798");

Pictorial Presentation:

SQL INSERT INTO STATEMENT

See our Model Database

SQL INSERT INTO Statement can be used in various forms. In the consequent pages, we have discussed those with the example, explanation, and pictorial presentations. Have a go through -

Insert null

You can use INSERT INTO statement to insert NULL Values.

Inserting the result of a query in another table

What if you want to insert data into a table while collecting data from another SQL query?

Insert using subqueries

You can use SUBQUERIES to INSERT data.

Insert using nested subqueries with any operator

You can even use NESTED SUBQUERIES with ANY OPERATOR to insert data.

Here is a new document which is a collection of questions with short and simple answers, useful for learning SQL as well as for interviews.