Reputation: 23
I want to import data from a text file into MySQL Database, Here my requirement is to auto increment the ID (Also the Primary Key) column without importing it from the text file. I also have set ID column as Primary Key, Non-Negative and Auto-Incrementing.
The code I have used
use vehicledetails;
LOAD DATA INFILE 'C:/ProgramData/MySQL/MySQL Server 8.0/Uploads/Test.txt'
INTO TABLE vehiclespeeddetail
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\r\n';
When I run the above code I get an error saying
Error Code: 1265. Data truncated for column 'ID' at row 1
My Text file is of as follows
I want an output with an Auto Incrementing ID Column by importing data from the above text file:
Upvotes: 0
Views: 352
Reputation: 14666
With an explicit list of columns that excludes the Auto increment column:
use vehicledetails;
LOAD DATA INFILE 'C:/ProgramData/MySQL/MySQL Server 8.0/Uploads/Test.txt'
INTO TABLE vehiclespeeddetail
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\r\n'
(`Date`, `Time`, `NoPlate`, `CurrentSpeed`, `MaxSpeed`, `OverspeedDetection`);
Upvotes: 1