Hello and welcome to our community! Is this your first visit?
Register
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
    Location
    Los Angeles
    Posts
    40
    Thanks
    2
    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
    Posts
    25,020
    Thanks
    75
    Thanked 4,323 Times in 4,289 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:
    Code:
    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:
    Code:
    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
    •