SQL INSERT INTO Examples

Let’s look at some examples of INSERT INTO statement in SQL to understand it better.

Suppose there is a Student database and we want to add values. 

ROLL_NO NAME  ADDRESS  PHONE AGE
1 Ram Delhi xxxxxxxxxxxxxx 18
2 RAMESH GURGAON xxxxxxxxxxxxxx 18
3 SUJIT ROHTAK xxxxxxxxxxxxxx 20
4 SURESH ROHTAK xxxxxxxxxxxxxx 18
3 SUJIT ROHTAK xxxxxxxxxxxxxx 20
2 RAMESH GURGAON xxxxxxxxxxxxxx 18

Inserting Only New Values Using INSERT INTO Example

If we want to insert only values then we use the following query:

Query:

INSERT INTO Student 
VALUES ('5','HARSH','WEST BENGAL', 'XXXXXXXXXX','19');

Output: 

The table Student will now look like this:

ROLL_NO NAME ADDRESS PHONE Age
1 Ram Delhi XXXXXXXXXX 18
2 RAMESH GURGAON XXXXXXXXXX 18
3 SUJIT ROHTAK XXXXXXXXXX 20
4 SURESH Delhi XXXXXXXXXX 18
3 SUJIT ROHTAK XXXXXXXXXX 20
2 RAMESH GURGAON XXXXXXXXXX 18
5 HARSH WEST BENGAL XXXXXXXXXX 19

Insert Values to Specified Columns Using INSERT INTO Example

If we want to insert values in the specified columns then we use the following query:

Query:

INSERT INTO Student (ROLL_NO, NAME, Age) 
VALUES ('5','PRATIK','19');

Output:

The table Student will now look like this:

ROLL_NO NAME ADDRESS PHONE Age
1 Ram Delhi XXXXXXXXXX 18
2 RAMESH GURGAON XXXXXXXXXX 18
3 SUJIT ROHTAK XXXXXXXXXX 20
4 SURESH Delhi XXXXXXXXXX 18
3 SUJIT ROHTAK XXXXXXXXXX 20
2 RAMESH GURGAON XXXXXXXXXX 18
5 PRATIK null null 19

Notice that the columns for which the values are not provided are filled by null. Which are the default values for those columns?

SQL INSERT INTO Statement

The INSERT INTO statement in SQL is used to add new records to a table in a database. It is a fundamental command for data insertion and is used to insert new data into tables.

Similar Reads

Syntax

There are two syntaxes of INSERT INTO statements depending on the requirements. The two syntaxes are:...

SQL INSERT INTO Examples

Let’s look at some examples of INSERT INTO statement in SQL to understand it better....

Insert Multiple Rows in a table using Single SQL Statement

You can use the given technique to insert multiple rows in a table in a single query. This saves time for writing queries, and reduces the margin error....

SQL INSERT INTO SELECT

The SQL INSERT INTO SELECT statement is used to copy data from one table and insert it into another table. The use of this statement is similar to that of the INSERT INTO statement. The difference is that the SELECT statement is used here to select data from a different table. The different ways of using INSERT INTO SELECT statement are shown below:...

INSERT INTO SELECT Syntax

There are two syntaxes for using INSERT INTO SELECT statement, depending on it’s use....

SQL INSERT INTO SELECT Examples

Let’s look at some examples of INSERT INTO SELECT statement to understand it better....

Important Points About SQL INSERT INTO Statement

The INSERT INTO statement is used to add new records to a table in a database It allows inserting multiple records in a single statement by providing multiple sets of values. If you don’t specify the column names, the statement assumes all columns and the values must be in the same order as the table definition. Columns not included in the INSERT statement will be filled with default values, which are typically NULL. statementscondition....