Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to insert data in a batch? [duplicate]

In MySQL, I could fire off these statements to insert 5 rows in one shot:

CREATE TABLE t (id int primary key auto_increment)
INSERT INTO t VALUES (DEFAULT),(DEFAULT),(DEFAULT),(DEFAULT),(DEFAULT)

How can I do the same thing in MS SQL Server?

P.S. The reason that the suggested duplicate doesn't solve the problem is that it has tables with non-identity columns. My Table only has an identity column.

like image 485
AngryHacker Avatar asked Dec 21 '15 07:12

AngryHacker


1 Answers

If you have this definition:

CREATE TABLE t (id int IDENTITY(1,1) PRIMARY KEY)

Then you can do this:

INSERT t DEFAULT VALUES
INSERT t DEFAULT VALUES
INSERT t DEFAULT VALUES
INSERT t DEFAULT VALUES
INSERT t DEFAULT VALUES
like image 107
Arion Avatar answered Oct 24 '22 20:10

Arion