top of page
Writer's pictureEkta Aggarwal

INSERTing data into SQL table

Syntax:

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

Syntax:

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

VALUES

(Row1-value1,Row1-value2,Row1-value3,...),

(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
VALUES
('ABCD','F',22,'Barcelona',20000),
('XYZ','M',18,'Madrid',13000);

SELECT * FROM mytable2;

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

INSERT INTO mytable2(CustName,Gender)
VALUES
('PQR','F'),
('EFG','M');

SELECT * FROM mytable2;

Comments


bottom of page