Import data from ascii file to database in the same row order

  • Hello everyone,

    I want to ensure something. I must insert some files in my SQL Server Database. I use the traditional way. Oledb connection to SQL Server and fast load. I also have added an identity column ( INT IDENTITY (1,1) ) to have an ordering 1,2,3 etc.

    My question is: Are the rows in the database (destination) in the same order imported as they are in the files? Does the identity column that I have added, help me to have the right order? I checked some data and to be honest I see the exact same ordering as it is in the files... But I must 100% sure. I think about to add an identity column to the files but I know it's not the best practice... I am really thankful for any advice.

    Please help! 🙂

    Thank you a lot!

  • Tables don't have an order.

    The identity might help if you put a clustered index on it and if all the queries on the table use ORDER BY ID.

    Need an answer? No, you need a question
    My blog at https://sqlkover.com.
    MCSE Business Intelligence - Microsoft Data Platform MVP

  • rena24 (9/9/2014)


    Hello everyone,

    I want to ensure something. I must insert some files in my SQL Server Database. I use the traditional way. Oledb connection to SQL Server and fast load. I also have added an identity column ( INT IDENTITY (1,1) ) to have an ordering 1,2,3 etc.

    My question is: Are the rows in the database (destination) in the same order imported as they are in the files? Does the identity column that I have added, help me to have the right order? I checked some data and to be honest I see the exact same ordering as it is in the files... But I must 100% sure. I think about to add an identity column to the files but I know it's not the best practice... I am really thankful for any advice.

    Please help! 🙂

    Thank you a lot!

    It would be better to add a row number to your source data and insert that to your target table, just to be sure. You cannot guarantee that your method will always work.

    Or have a look here[/url] for an example of how to create a row number as the data passes through the SSIS pipeline.

    If you haven't even tried to resolve your issue, please don't expect the hard-working volunteers here to waste their time providing links to answers which you could easily have found yourself.

  • Hello everyone and thank you for the Answers!

    Phil your solution is great!!! Thats exacrly what I need! Quick and clear!

    Thank you very very much!

  • rena24 (9/10/2014)


    Hello everyone and thank you for the Answers!

    Phil your solution is great!!! Thats exacrly what I need! Quick and clear!

    Thank you very very much!

    🙂 Thanks for posting back with the nice feedback.

    If you haven't even tried to resolve your issue, please don't expect the hard-working volunteers here to waste their time providing links to answers which you could easily have found yourself.

  • You saved me! Thank you again! :-):-):-)

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

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