SQL - INSERT Query

The SQL INSERT query is used to insert a new record into the table. We can add a new record to the table in two ways.

INSERT Query Syntax :

The syntax of the INSERT Query statement is −

INSERT INTO TABLE_NAME (column1, column2, column3,...columnN)  
VALUES (value1, value2, value3,...valueN);

Here column1, column2, column3, ... columnN is the name of the column and the value1, value2, value3, ... valueN is the value of the corresponding column.

We do not have to specify by column name, if you are adding values for all the columns of the table.
NOTE:- Value should be in same order as the columns in the table.

INSERT INTO TABLE_NAME VALUES (value1,value2,value3,...valueN);



INSERT Query Example :

Consider the Customer table with the following records -

CustomerID CustomerName Age Address CustomerSalary
1 Aarav 28 Udaipur 28000
2 Vivaan 25 Mumbai 30000
3 Reyansh 28 Chennai 35000
4 Muhammad 24 Udaipur 50000
5 Sai 30 Mumbai 27000


TEST CASE 1 :- The following code is an example, which would add new record to Customer table.

INSERT INTO Customer (CustomerName, Address, CustomerSalary)
VALUES ('Sarthak', 'Delhi', '31000');


The result for the respective sql query is as follows −

CustomerID CustomerName Age Address CustomerSalary
1 Aarav 28 Udaipur 28000
2 Vivaan 25 Mumbai 30000
3 Reyansh 28 Chennai 35000
4 Muhammad 24 Udaipur 50000
5 Sai 30 Mumbai 27000
6 Sarthak null Delhi 31000



TEST CASE 2:- The following code is an example, which would add new record to Customer table.

INSERT INTO Customer 
VALUES ('Rushil', 24, 'Indore', 20000);


The result for the respective sql query is as follows −

CustomerID CustomerName Age Address CustomerSalary
1 Aarav 28 Udaipur 28000
2 Vivaan 25 Mumbai 30000
3 Reyansh 28 Chennai 35000
4 Muhammad 24 Udaipur 50000
5 Sai 30 Mumbai 27000
6 Rushil 24 Indore 20000





Visit :


Discussion



* You must be logged in to add comment.

عمر نزار ادريس عبدالله الحيالي
How can you insert NULL values in a ?column while inserting the data NULL values in SQL can be inserted in