Bulk Insert

  • Hello,

    I have to use an BULK INSERT into SQL-SERVER.

    I Have a text file and a table.

    In this text file, i have RowDelimiters and Field Delimiters as a comma ( Row Delimiter is comma and \n ).

    I create the Bulk Insert, but in the table, there's a field ( ID ) that is an integer ( is an auto-incrent field ) and that don't exist in the text-field.

    May someone help me posting the right commands to use to let the bulk insert to work without asking also for the ID field?

    Thanks a Lot! 🙂

  • Create a format (.fmt) file and pass it to the bcp command.

    Far away is close at hand in the images of elsewhere.
    Anon.

  • Try this:

    BULK INSERT TableName FROM 'FullPathToFile'

    WITH (DATAFILETYPE = 'char',

    FIELDTERMINATOR = ',',

    ROWTERMINATOR = ',\n',

    KEEPIDENTITY)

    I assume the rowdelimiter is a comma, but change it if you need.

  • racosta,

    Thats ok if you are supplying the value of the identity column. If not and you want sql to generate the value then you need to use a format file.

    BTW I can successfully use a format file in this way with bcp but never with 'BULK INSERT'.

    Far away is close at hand in the images of elsewhere.
    Anon.

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

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