Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

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())
share|improve this question
add comment

1 Answer

up vote 17 down vote accepted

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; 
share|improve this answer
4  
+1 for (ab) in using. –  hims056 Mar 13 '13 at 11:45
    
Awesome merge tip! –  Rohan Mar 13 '13 at 14:14
3  
For multiple rows you could also use GO 1000 - not exactly the same thing but much less hassle than trying to memorize that syntax. :-) –  Aaron Bertrand Mar 13 '13 at 14:24
    
Yes, GO 1000 seems to be much easier. Thanks for that. –  jrara Mar 13 '13 at 15:10
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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