SQL INSERT

This statement is used to insert new values or records in the database.

 

Syntax:

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

 

Example Database:

This is  customers  table.

id name Location
1 Kailash Delhi
2 Amit Haryana
3 Siddarth Noida
4 Vikas Noida

 


 

INSERT Example:

Example1: Insert new customer records in customers table.

Syntax:

INSERT INTO customers (id, name, location)
VALUES (5, 'Ranjeet', 'Faridabad');

 

Result:

id name Location
1 Kailash Delhi
2 Amit Haryana
3 Siddarth Noida
4 Vikas Noida
5 Ranjeet Faridabad

 

Example2:  You may not need to specify the column(s) name in the SQL query if you are adding values for all the columns of the table. But make sure the order of the values is in the same order as the columns in the table.

Syntax:

INSERT INTO customers VALUES (6, 'Saba', 'Delhi');

 

Result:

id name Location
1 Kailash Delhi
2 Amit Haryana
3 Siddarth Noida
4 Vikas Noida
5 Ranjeet Faridabad
6 Saba Delhi