Top SQL Queries to Insert Single-row and Multi-rows

Top SQL Queries to Insert Single-row and Multi-rows
Photo by Oleksandr Pidvalnyi on Pexels.com

Here are the SQL queries to insert single-row and multiple rows. The insert command with values you usually insert single row into the table. Similarly, you can insert multiple rows.

INSERT SQL Query

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

The my_table let us say has four columns. Those are Name, Salary, City and EmpCode. The way of insert with single line of values is called single-row insert.

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

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

INSERT Multi-row

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

After each value line you need to use 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.