top of page
  • Ekta Aggarwal

INSERTing data into SQL table


Following is the syntax to feed data into a SQL table:


INSERT INTO table_name (column1,column2,column3,...)



(Row2-value1,Row2-value2,Row2-value3,...), ..., (RowN-value1,RowN-value2,RowN-value3,...);

Special Syntax:

If you are feeding values into all the columns and in the same order as they appear in the dataset then you can skip the (column1,column2, column3,...) i.e.

INSERT INTO table_name VALUES (Row1-value1,Row1-value2,Row1-value3,...), (Row2-value1,Row2-value2,Row2-value3,...), ..., (RowN-value1,RowN-value2,RowN-value3,...);

Let us create a new table 'mytable'

CREATE TABLE mytable2(
CustName varchar(100),
Gender char(1),
Age numeric,
City varchar(100),
Salary	numeric);

Let us insert data into all the columns:

INSERT INTO mytable2

SELECT * FROM mytable2;

Now we will insert data only into 2 columns:CustName and Gender.

INSERT INTO mytable2(CustName,Gender)

SELECT * FROM mytable2;

bottom of page