Inserting Record in a Table


☞ To insert a new record into a table in RDBMS, we use INSERT INTO command.



Inserting data for all the columns in a table

Syntax :

INSERT INTO <table_name> 
VALUES ( <value1>, <value2>,.......); 

OR

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

Example :

INSERT INTO student 
VALUES ( 1, "Ruchi", F, "1987-04-04", 5000.50); 

 OR 

INSERT INTO student (Roll_no, Name, Gender, DOB, Fees)
VALUES ( 1, "Ruchi", F, "1987-04-04", 5000.50); 


Inserting data into particular columns in a table

Syntax :

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

Example :

INSERT INTO student (Roll_no, Name, DOB)
VALUES ( 1, "Ruchi",  "1987-04-04"); 
Note : Remaining column will hold the values as NULL.

Inserting NULL values into a table

Syntax :

INSERT INTO <table_name> 
VALUES ( <value1>, <value2>,.......); 

OR

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

Example :

INSERT INTO student 
VALUES ( 1, "Ruchi", NULL, "1987-04-04", NULL); 

 OR 

INSERT INTO student (Roll_no, Name, Gender, DOB, Fees)
VALUES ( 1, "Ruchi", NULL, "1987-04-04", NULL); 


Inserting multiple records for all the columns in a table

Syntax :

INSERT INTO <table_name> 
VALUES ( <value1>, <value2>,.......),
( <value1>, <value2>,.......),
( <value1>, <value2>,.......); 

Example :

INSERT INTO student
VALUES ( 2, "Ankit", M, "1989-03-14", 5085.50),
( 3, "Deepika", F, "1988-10-08", 4963.50),
( 4, "Devansh", M, "1988-08-115", 4526.00);