;

SQL INSERT INTO


In this tutorial, we will learn how to INSERT record into a  table of a database using  SQL.

SQL INSERT INTO Statement

SQL INSERT INTO statement is used to insert a new record or new row in a table of the database.

There are two ways to insert or adding a new row to a table:

  • By specifying the column name
  • without specifying column names

Syntax using 1st Way - By Specifying Column names

Syntax - By specifying column names
INSERT INTO tableName(column1, column2,...columnN)
VALUES(value1, value2,...valueN);

Syntax using 2nd Way - without specifying column names

Syntax - Without specifying column names
INSERT INTO tableName
VALUES(value1, value2,...valueN);

Examples

Example - INSERT INTO By Specifying Column names
INSERT INTO Employee(ID,EmpName,City,Country,Gender,Salary)
VALUES (1,'Shankar','Delhi','India','male',25000);

INSERT INTO Employee(ID,EmpName,City,Country,Gender,Salary)
VALUES (2,'Sourabh','Delhi','India','male',30000);

INSERT INTO Employee(ID,EmpName,City,Country,Gender,Salary)
VALUES (3,'Ranvijay','Mumbai','India','male',15000);

INSERT INTO Employee(ID,EmpName,City,Country,Gender,Salary)
VALUES (4,'kapil','Noida','India','male',25000);

INSERT INTO Employee(ID,EmpName,City,Country,Gender,Salary)
VALUES (5,'shalini','Jaipur','India','female',18000);

INSERT INTO Employee(ID,EmpName,City,Country,Gender,Salary)
VALUES (6,'Rakesh','Faridabad','India','male',23000);

Example - For Selecting Inserted Records
//For Selecting Records use this SELECT statement
SELECT * FROM Employee
Output 
ID EmpName City Country Gender Salary
1 Shankar Delhi India male 25000
2 Sourabh Delhi India male 30000
3 Ranvijay Mumbai India male 15000
4 Kapil Noida India male 25000
5 Shalini Jaipur India female 18000
6 Rakesh Faridabad India male 23000
Example - INSERT INTO without specifying column names
INSERT INTO Employee
VALUES (7,'Akshay','Mumbai','India','male',21000);

INSERT INTO Employee
VALUES (8,'Sarah','Neywork','US','female',76000);

INSERT INTO Employee
VALUES (9,'Rocky','Noida','India','male',28000);
Output
ID EmpName City Country Gender Salary
1 Shankar Delhi India male 25000
2 Sourabh Delhi India male 30000
3 Ranvijay Mumbai India male 15000
4 Kapil Noida India male 25000
5 Shalini Jaipur India female 18000
6 Rakesh Faridabad India male 23000
7 Akshay Mumbai India male 21000
8 Sarah New York US female 76000
9 Rocky Noida India male 28000