- Insert command is used to insert records into the database table.
Syntax:
INSERT INTO <table_name> VALUES(val1,val2, val3,…,valN);
Example:
INSERT INTO student VALUES(1,’ABC’,’Ahmedabad’);
- It can be helpful for inserting record for all the columns so, there is no need to specify column name.
- Values for particular column should be in the same order as of in the table structure.
- Remember to enclose string value into a single quote(‘’)
-
Inserting record for specific columns:
Syntax:
INSERT INTO <table_name>(column1,column2,…,columnN) VALUES(val1,val2,…, valN);
Example:
INSERT INTO student(std_no,std_name) VALUES(2,’XYZ’);
- We can provide a list of column for which we want to insert data.
-
Reading data from Console:
Syntax:
INSERT INTO <table_name> VALUES (&column1, &column2..,&columnN);
Example:
INSERT INTO student VALUES(&std_no, ’&std_name’, ’&city’);
-
Reading data for specific column:
Syntax:
INSERT INTO <table_name> (column1,column2,…,column N) VALUES (&column1, &column2,….., &column N);
Example:
INSERT INTO student(std_no, std_name, city)
VALUES(&std_no, ’&std_name’, ’&city’);
- ‘&’ sign can be used to scan value from the console.
- Values for the column must be in the same order as of the given list.
- We can also insert default value for some records in certain columns automatically. To learn more on how default value concept works, please read our article “Default Value”.