SQL: Is it quicker to insert sorted data into a table?

Posted by AngryWhenHungry on Stack Overflow See other posts from Stack Overflow or by AngryWhenHungry
Published on 2010-05-26T09:23:26Z Indexed on 2010/05/26 14:31 UTC
Read the original article Hit count: 175

Filed under:
|

A table in Sybase has a unique varchar(32) column, and a few other columns. It is indexed on this column too. At regular intervals, I need to truncate it, and repopulate it with fresh data from other tables.

insert into MyTable  
  select list_of_columns  
  from OtherTable  
  where some_simple_conditions  
  order by MyUniqueId  

If we are dealing with a few thousand rows, would it help speed up the insert if we have the order by clause for the select? If so, would this gain in time compensate for the extra time needed to order the select query?

I could try this out, but currently my data set is small and the results don't say much.

© Stack Overflow or respective owner

Related posts about sql

Related posts about sybase