11

If I create a table with an identity column as primary key, and all the other columns have default values, for example

create table rr (id int identity(1,1) primary key, dt datetime default getdate())

1 Answer 1

22

To insert a single row

INSERT INTO RR DEFAULT VALUES;

It is possible to insert multiple rows of default values by (ab)using MERGE

MERGE INTO RR
USING (SELECT TOP 1000 *
       FROM   master..spt_values) T
ON 1 = 0
WHEN NOT MATCHED THEN
  INSERT
  DEFAULT VALUES; 
2
  • 5
    For multiple rows you could also use GO 1000 - not exactly the same thing but much less hassle than trying to memorize that syntax. :-) Mar 13, 2013 at 14:24
  • Yes, GO 1000 seems to be much easier. Thanks for that.
    – jrara
    Mar 13, 2013 at 15:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.