no-email wrote:[color=blue]
> "David Gugick" <davidg-nospam@imceda.com> wrote:
>[color=green]
>> Why does the order of the rows inserted into the table matter in your
>> case? Relational databases don't understand row order. If you need
>> them sorted in some way after the import, you can create a clustered
>> index on the table to get the rows ordered in a way that helps your
>> queries perform better.
>>
>> In general, I think BCP processes the rows in the file sequentially.
>> But again, I'm not clear on why this matters.
>>
>> Could you elaborate on the exact issue you are trying to avoid.[/color]
>
> I am trying to load a text file sequentially in order to perform text
> manipulations using T-SQL that do depend on the exact order. I would
> be happy with simply adding a line number to each line of the Unicode
> text file, and then loading the file with line number determining the
> order, but I want to avoid programming in another language if
> possible. Eventually the loaded text would be converted to proper
> relational tables. This doesn't have to do with improving
> performance. Does this help?
> Thanks.[/color]
Yes. It sounds like you have rows in a specific order that will need to
be processed once on SQL Server. You want to preserve the order of rows
in the file so the rows can be processed in the same order once on SQL
Server.
In order to do this in any relational database, you need a sort key.
There is never a guarantee that a query you run without an ORDER BY will
return rows in the same order in any consistent way.
My understanding is that BCP feeds the rows in the order they appear in
a file. I can't imagine any reason it would or could do it differently.
In that case, you want to insert the data into a table that contains an
IDENTITY column. You can then use that key for your ORDER BY when
processing the rows from whatever process does that.
--
David Gugick
Imceda Software
www.imceda.com