My need is very simple. How to add a serial number or id(probably an auto_increment value I guess) for each row being inserted in a MySQL table?
我的需要很简单。如何为MySQL表中插入的每一行添加序列号或id(可能是我猜的auto_increment值)?
To be more specific, I've a CSV file from which I store the separate field values into the database using LOAD DATA. What all I need is, if there are totally 2000 rows being loaded from the CSV file, each row has to be automatically inserted with a unique serial number like 1,2,3,etc...
更具体地说,我有一个CSV文件,我使用LOAD DATA将单独的字段值存储到数据库中。我需要的是,如果从CSV文件中加载了2000行,每行必须自动插入一个唯一的序列号,如1,2,3等...
Please help me with the exact query that I'll be needing rather than a syntax.
请帮助我提供我需要的确切查询,而不是语法。
Thanks in anticipation.
谢谢你的期待。
1 个解决方案
#1
0
Add AUTO_INCREMENT
to your id column (create it if you need to). It will then do this automatically for you:
将AUTO_INCREMENT添加到您的id列(如果需要,创建它)。然后它会自动为您执行此操作:
ALTER TABLE tablename MODIFY id INTEGER NOT NULL AUTO_INCREMENT;
#1
0
Add AUTO_INCREMENT
to your id column (create it if you need to). It will then do this automatically for you:
将AUTO_INCREMENT添加到您的id列(如果需要,创建它)。然后它会自动为您执行此操作:
ALTER TABLE tablename MODIFY id INTEGER NOT NULL AUTO_INCREMENT;