Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Feb 2009
    Los Angeles
    Thanked 1 Time in 1 Post

    CSV upload - AUTO INCREMENT field?

    I need to upload a CSV file to a new table. If the Primary id field is auto incremented, what do I fill the column cells with in Excel? I've tried "0", NOT NULL, and just leaving the column blank.

    I could just fill it in with numbers on the file in Excel, but what if I'm adding to an existing table? Isn't there something more automatic?

    This doesn't work the same as leaving that field blank in PHPMyAdmin, which is what I'm using to upload the file.

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Thanked 4,731 Times in 4,693 Posts
    I *think* you need to use NULL.

    Certainly when you use a simple SQL command and you include the autoincrement column in the list of fields, you use NULL in the values. That is:
    INSERT INTO table ( autoinc, f1, f2 )
    VALUES( null, 'xxx', 'yyy' )
    Dunno if a textual NULL in the CSV file will work, though.

    Why not just omit the field???

    The SQL I gave above is semantically the same as:
    INSERT INTO table ( f1, f2 )
    VALUES( 'xxx', 'yyy' )
    Haven't done this with MySQL. Have with SQL Server, but SQL Server's DTS is very very flexible.


    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts