INF: Sorting Data Out of SQL Server

Last reviewed: April 25, 1997
Article ID: Q45661

The information in this article applies to:

  - Microsoft SQL Server version 4.2 for OS/2

The following steps describe a process for sorting records outside of SQL Server:

  1. Use BCP to unload the table. The rows will appear in the order in which they were originally inserted or in the order of the clustered index (if there is one).

  2. Use TRUNCATE TABLE to purge all of the data from the table.

  3. Sort the rows with the utility of your choice and reload them. If no clustered index exists when the table is loaded, the rows will be stored in the order loaded. If a clustered index exists, the rows will be stored in clustered index order. The loading process will be slower with indexes because the index(es) must be updated every time a row is added.

    If a clustered index is created after the table is loaded, the entire table will be copied and sorted using the free pages within the database. This will be done regardless of whether or not the rows were sorted externally before they were loaded.


Additional query words: BCP
Keywords : kbtool SSrvBCP
Version : 4.2
Platform : OS/2


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: April 25, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.