Solace
Solace

Reputation: 9010

How to bulk load data such without entering values for the column indexed "auto-increment"

Following is the code to bulk load data from a text file.

LOAD DATA LOCAL INFILE 'C:\\file.txt'
    INTO TABLE datatable;

I have a table with two columns, an attribute and id, the primary key with the AUTO_INCREMENT index. Values for the attribute are given (one line for each row) in the text file.

I want the id (indexed "AUTO_INCREMENT) to be inserted itself and then increment itself. I think it is possible, but what will be the way to do it?

Upvotes: 1

Views: 176

Answers (2)

Robert
Robert

Reputation: 1316

You could raw import everything from .txt into the Database (with your given command), so you have just the attributes there and then afterwards add the ID field later.

ALTER TABLE datatable ADD `id` MEDIUMINT NOT NULL AUTO_INCREMENT KEY

For detail explanation there is already a question for that: Add a column to existing table and uniquely number them

Upvotes: 2

Andy W
Andy W

Reputation: 2192

Try this one:

LOAD DATA LOCAL INFILE 'C:\\file.txt'
    INTO TABLE datatable(`attribute`);

If this won't work, a table structure and a sample rows of your file.txt would help.

Upvotes: 2

Related Questions