Facebook Page Twitter Page LinkedIn Page
× SQL Tutorial SQL Advanced SQL Database SQL Resources


The SQL INSERT INTO statement is used to insert a new record in a table. There are two ways of using INSERT INTO statement which are mentioned below.

Syntax

The below syntax specifies column names and respective values to be inserted.

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

The below syntax specifies values only. Therefore, it is essential to specify values in the same order as the columns in the table.

INSERT INTO table_name 
VALUES (value1, value2, value3, ...);

Example:

Consider a database tables called Employee with the following records:

EmpIDNameCityAgeSalary
1JohnLondon253000
2MarryNew York242750
3JoParis272800
4KimAmsterdam303100
5RameshNew Delhi283000
6HuangBeijing282800

  • To insert a new record in the Employee table, the SQL query is:

    INSERT INTO Employee (EmpID, Name, City, Age, Salary)
    VALUES (7, 'Suresh', 'Mumbai', 29, 2900);
    
    OR
    
    INSERT INTO Employee 
    VALUES (7, 'Suresh', 'Mumbai', 29, 2900);
    

    Now the Employee table will contain following records:

    EmpIDNameCityAgeSalary
    1JohnLondon253000
    2MarryNew York242750
    3JoParis272800
    4KimAmsterdam303100
    5RameshMumbai282900
    6HuangBeijing282800
    7SureshMumbai292900
  • Insert Data Only in Specified Columns: To insert data in specified columns, it is necessary to specify column names. Please see the SQL code below:

    INSERT INTO Employee (EmpID, Name, Age)
    VALUES (7, 'Suresh', 29);
    

    Now the Employee table will contain following records:

    EmpIDNameCityAgeSalary
    1JohnLondon253000
    2MarryNew York242750
    3JoParis272800
    4KimAmsterdam303100
    5RameshMumbai282900
    6HuangBeijing282800
    7SureshNULL29NULL