< Sql Tutorial

Sql Insert

← Previous Next →


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


The SQL INSERT INTO Statement

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

It is possible to write the INSERT INTO statement in two forms.

The first form does not specify the column names where the data will be inserted, only their values:

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

The second form specifies both the column names and the values to be inserted:

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

Lets see an example, Consider a table Student with following fields.

S_id S_Name age

INSERT into Student values(101,'Adam',15);

The above command will insert a record into Student table.

S_id S_Name age
101 Adam 15

Example to Insert NULL value to a column

Both the statements below will insert NULL value into age column of the Student table.

INSERT into Student(id,name) values(102,'Alex');

Or,

INSERT into Student values(102,'Alex',null);

The above command will insert only two column value other column is set to null.

S_id S_Name age
101 Adam 15
102 Alex  

Example to Insert Default value to a column

INSERT into Student values(103,'Chris',default)
S_id S_Name age
101 Adam 15
102 Alex  
103 chris 14

Suppose the age column of student table has default value of 14. Also, if you run the below query, it will insert default value into the age column, whatever the default value may be.

INSERT into Student values(103,'Chris')
← Previous Next →