SQL Query to Insert Multiple Rows Simplified

Here are the SQL queries to insert single-row and multiple rows.

INSERT SQL Query

Here is an SQL query to insert a single row at a time.

INSERT INTO MY_TABLE 
VALUES('RAMA', 20000, 'HYDERABAD', 1001);

Say, the my_table table has four columns VIZ: Name, Salary, City, and EmpCode. The way of inserting with a single line of values is called a single-row insert.

And you can insert a NULL value into a table. The optional thing is you can avoid the column names if the values are in the same order as Table columns.

INSERT INTO MY_TABLE 
(Name, Salary, City, EmpCode)
VALUES('RAMA', 20000, 'HYDERABAD', 1001);

INSERT Multi-row

Here is an SQL query to insert multiple rows at a time.

Inserting multi-rows saves you time, and you can avoid the Values keyword multiple times of writing.

After each value line, you need to use the comma ‘,’. The semi-colon just use only once (at the end of SQL query).

INSERT INTO MY_TABLE 
(Name, Salary, City, EmpCode)
VALUES('RAMA', 20000, 'HYDERABAD', 1001),
        ('RAVI', 30000, 'DELHI', 1002),
           ('RANI', 40000, 'LUKNOW', 1003);

References

Related posts

Author: Srini

Experienced software developer. Skills in Development, Coding, Testing and Debugging. Good Data analytic skills (Data Warehousing and BI). Also skills in Mainframe.