Suggesition in the query performance

  • Hi,

    I have a query like

    insert into table1 select * from table2 order by col1

    where col1 is a cluster index.

    according to my view there is no need of the order by clause, which will reduce the effeciency of the statement. But since its a insert statement which insert data in clustered index, my friend says it will be effecient if we use the order by clause.

    Any suggesitions in this. Thank you.

    with smiles

    Santhosh

  • The order by can be benificial if you order in the table1 clustered index.

  • Neither you nor your friend are correct actually. The order by clause is a no-op, since the data is already sorted in that order and you are selecting all rows. So it does not reduce or increase the efficiency of the statement. Look at the execution plans with and without using the order by. They will be identical.

    However, I see no reason to have the order by statement. The order of which rows are stored in a table is unimportant, it is when you query data that you might want to order it.

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply