Given the following code:
declare @StatementTable table
(
ID int identity not null,
StatementText nvarchar(max) not null
);
insert into @StatementTable (StatementText)
select
StatementToExecute
from
dbo.MyTable
order by
MyColumn
As long as the dbo.MyTable
does not change and MyColumn
is unique, will the ID values in the @StatementTable
table variable be consistent from execution to execution?
In other words, does providing an order by
clause guarantee consistent order of insert?
When used with a SELECT...INTO statement to insert rows from another source, the ORDER BY clause does not guarantee the rows are inserted in the specified order.
If it matters, I'm on SQL Server 2017...