Offhand, I cannot think of a way of doing this with one statement. You could use the table master.dbo.spt_values
:
set identity_insert #test1 off;
insert into #test1 (test_id)
select top (100) row_number() over (order by (select null))
from master.dbo.spt_values;
set identity_insert #test1 on;
The specific problem is that select
needs to return something, and that something can't be a non-value for a non-column. And the alternative values
syntax only inserts one row at a time.
You might be better off doing:
create table #test1 (
test_id int identity(1, 1) primary key,
dummary varchar(1)
);
insert into #test1 (dummy)
select top (100) cast(NULL as varchar(1))
from master.dbo.spt_values;
This uses a minimal amount of space, because a NULL
varchar()
only occupies space for the NULL
bit.
For your code, default values
will work:
WHILE @i<@numRows
begin
INSERT #TEST1 DEFAULT VALUES
SET @i=@i+1
end