Oleg,
insert into #n
select
top 3 row_number() over (order by [object_id])
from sys.objects;
is not the same as
insert #n values (1)
insert #n values (2)
insert #n values (3)
Should you check the @@rowcount after performing your select, it will return 3, meaning that there were 3 rows affected by your SQL call.
In the individual inserts,it will return a 1 after the last insert command.
@@ROWCOUNT changes after each SQL call, which is why it needs to be immediately after any command which you want to check the rowcont of.
@@ROWCOUNT returns the specific number of rows either returned from a query or affected by a transaction. The value of @@ROWCOUNT is ALWAYS the value of the immediate preceeding SQL call. Thus, your example is selecting 3 rows and inserting them as a batch. The QOD is performing 3 seperate inserts.
Steve Jimmo
Sr DBA
“If we ever forget that we are One Nation Under God, then we will be a Nation gone under." - Ronald Reagan