View Full Version : CSV upload - AUTO INCREMENT field?

04-18-2009, 01:58 AM
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.

Old Pedant
04-18-2009, 07:03 AM
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.