Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Import/Export (DTS) and Replication (2000)
 Bulk Insert in same order of the text file

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2006-02-16 : 07:59:40
Srirup writes "after doing a bulk insert, i need the data in the same order in the table as
it is present in the text file and i have a particular reason for it i.e

in my text file there are set of rows in a particular sequence which gets
inserted into a particular row of a table based on some criteria.
and then again there a new set of rows just below it.

now if the order is changed in the table after doing a bulk insert , then
data will be inserted in wrong tables.

so kindly tell me if there is a way to retain the same order in the table as
it is in the text file."

Kristen
Test

22859 Posts

Posted - 2006-02-16 : 08:16:43
Best bet would be to add an Identity column which will be given a sequentially increasing number for each row inserted; then you can ORDER BY that new column when you want to present the data in the original order.

Otherwise they is NO guarantee to the order that SQL presents the data - e.g. if you make a new query and SQL Server happens to have some of the data in memory, and has to get the rest from disk, then it will sequence the in-memory-data first, followed by the from-disk-data - but if you have an ORDER BY it will sequence it in that order, of course.

Kristen
Go to Top of Page
   

- Advertisement -