Import from a txt file

  • Hi I using a sql server 2000 I need a script to import from a csv file, I know how to use the wizard that is built in the sql server 2000 but this time I need the script for my application.

    My databe call "sport" and I have a table call game with 5 fields, also I need

    to append the records from the csv file to my table "sport" and my first field is an identity field and the others are a varchar.

     

    How can I do this, thank you...

     

  • Assuming that your text file doesn't contain the identity column values and the columns in the text file are in the correct order, try

    BULK INSERT Sport.dbo.game

       FROM 'C:\SourceFile.txt' --Change as appropriate

       WITH

          (

             FIELDTERMINATOR = ',',

             ROWTERMINATOR = '\n'

          )

    If the text file contains identity values you'll need to use the KEEPIDENTITY keyword.

    If the file is out of order you'll need to use a FORMATFILE.

     

     

Viewing 2 posts - 1 through 1 (of 1 total)

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