Preserving ORDER BY in SELECT INTO

前端 未结 8 734
南笙
南笙 2020-11-27 07:18

I have a T-SQL query that takes data from one table and copies it into a new table but only rows meeting a certain condition:

SELECT VibeFGEvents.* 
INTO Vib         


        
8条回答
  •  时光取名叫无心
    2020-11-27 08:03

    What for?

    Point is – data in a table is not ordered. In SQL Server the intrinsic storage order of a table is that of the (if defined) clustered index.

    The order in which data is inserted is basically "irrelevant". It is forgotten the moment the data is written into the table.

    As such, nothing is gained, even if you get this stuff. If you need an order when dealing with data, you HAVE To put an order by clause on the select that gets it. Anything else is random - i.e. the order you et data is not determined and may change.

    So it makes no sense to have a specific order on the insert as you try to achieve.

    SQL 101: sets have no order.

提交回复
热议问题