Today, I have provided an article showing you how to insert multiple values into a table using a single query in SQL Server 2012. This is an interesting question. Many new developers write insert queries again and again to insert multiple records into a table. There is no need to use multiple insert queries; you can do it using a single query. There are two ways to do it. First we can use a simple insert query and another way is to use a union all to do it. Here, I have a table named EmployeeDetail with the columns emp_fname, emp_lname, emp_no, emp_add. I have constructed a query that inserts multiple values in table. Let's take a look at a practical example. The example is developed in SQL Server 2012 using the SQL Server Management Studio.
The table looks as in the following:

1. Insert multiple values in table using single INSERT Query
The syntax for inserting multiple values is:
INSERT INTO table-name (columns not mandatory)
query
Now the following is the simple example to insert multiple values in the table using a single INSERT Query.
INSERT INTO [EmployeeDetail] ( emp_fname,emp_lname ,emp_no,emp_add)
VALUES ('Ram','Kumar', 12, 'Delhi'),
('Smith', 'Kumar',15,'Capetown'),
('Crown', 'sharma',100,'Sydney'),
('Copper', 'verma',39,'Jamaica'),


bondili MANOJPosted Sep 28, 2021, 10:57 AM
What if any query fails