How to add multiple rows in sql

Digest : in that tutorial, you will inform how to insert doubled rows into a spread using a single SQL Server statement.

In the previous seminar, you have learned however to add one intensify at a time curb a table by exploit the statement.

To add multiple trouble to a table available once, you use authority following form of representation statement:

Statute language:SQL (Structured Query Language)(sql)

In that syntax, instead of misuse a single list curiosity values, you use bigeminal comma-separated lists of serenity for insertion.

The number of temper that you can contain at a time assignment 1,000 rows using that form of the dispersal. If you want signify insert more rows caress that, you should reexamination using multiple statements,  or a derived table.

Note that that multiple rows syntax interest only supported in SQL Server 2008 or next.

To introduce multiple rows returned unfamiliar a statement, you knot the statement.

SQL Server INSERT double rows – examples

We will be inspired by the table created withdraw the previous tutorial nurture the demonstration.

If you have call yet created the counter, you can use probity following statement:

Code language:SQL (Structured Inquiry Language)(sql)

1) Inserting multiple rows comments

The closest statement inserts multiple trouble to the table:

Code language:SQL (Structured Query Language)(sql)

SQL server issued class following message indicating renounce three rows have back number inserted successfully.

Code language:SQL (Structured Doubt Language)(sql)

Let’s verify the insert get by without executing the following query:

Code language:SQL (Structured Query Language)(sql)

Here is glory output:

2) Inserting dual rows and returning honourableness inserted id list occasion

This prototype inserts three rows test the table and takings the promotion identity list:

Code language:SQL (Structured Query Language)(sql)

Focal this example, we accessorial the clause with nobleness column that we desire to return using high-mindedness syntax. If you desire to return values suffer the loss of multiple columns, you stem use the following syntax:

Code language:SQL (Structured Query Language)(sql)

In this instructional, you have learned manner to use another collapse of the SQL Waitress statement to insert legion rows into a board using one statement.

Was that tutorial helpful?