Data Haunting

Easy Solutions Destination

By

Insert Multiple Rows in a single query in Sql Server

Recently I have faced this question in interview that how to add or insert multiple rows in a single query at once. So I have find out two different solutions for this query. Let’s see the solutions.

First we create one Table named as “EmployeeSalary” and which have three fields Id, Name and salary as per given in below query.

Easiest way for inserting multiple rows in a single query

The simple and easiest way ever I have find for inserting multiple rows is as below.

Above query is useful for adding multiple rows with specific column name which you want to insert in tables.

Above query is useful for adding multiple rows with all column with proper order which you want to insert in tables.

Insert multiple rows in a single query using Union All

In sql server multiple rows also can be inserted using Union All with Select Statement as below.

Above query is useful for adding multiple rows with specific column name which you want to insert in tables using Union All with Select statement.

Above query is useful for adding multiple rows with all column with proper order which you want to insert in tables using Union All with Select statement.

What is your opinion ?

Here we have seen the best way to insert multiple rows in a single query in sql server. If you have any query and question, you can comment or you can mail me.

Leave a Reply