Import text file without sorting

  • Any way to force BCP or Bulk Insert to import a text file in exact original row order?

    BCP and bulk insert and DTS all scramble the row order.

    Source is a tab-delimited text file. No key, contents are not usable for the ORDER hint. But order is important, it has headings, subheadings, subtotals, totals that will be utilized.

  • Has clustered key defined on some columns in your destination table?

  • Actually it should import in row order if there is no clustered index. Are you expecting to "select" the data and get it back in this order? There is no guarentee of this. If this is what you want, add an identity column to your table, import into it and select by the identity column.

    Steve Jones

    sjones@sqlservercentral.com

    http://www.sqlservercentral.com/columnists/sjones

    http://www.dkranch.net

  • Source file has 4 columns, destination table has 5 (4 plus identity primary key)

    Destination is dropped and created on each attempt, so no weird carryover or gaps in the identity column

    select * from table order by identity

    results in a scrambled version of the original

  • Forgot to mention - no indexes on imported columns

    Identity is primary key clustered

Viewing 5 posts - 1 through 4 (of 4 total)

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