I am wondering why this is coded this way.
declare @messages table ([SEQUENCE_ID] BIGINT, [MESSAGE_ID] BIGINT PRIMARY KEY CLUSTERED ([SEQUENCE_ID])) ; delete T output deleted.SEQUENCE_ID, deleted.MESSAGE_ID into @messages from (select top (65536) * from source order by SEQUENCE_ID) T ; What is the benefit of this over a simpler appearing SELECT ... INTO @messages ?
I can see one possible, that the DELETE T will free up any locks on the source table.
Another may be that SELECT INTO creates a heap, which then needs reordering on the key, so this reduces IO operations.
But what are the underlying reasons why this code is a good idea ?
I am assuming it is a good idea because it's in production code.