【发布时间】:2013-07-22 16:45:00
【问题描述】:
我有一个 EXISTING 表,其中有一个名为 ID 的主键和 6 个与发票相关的其他字段。我需要从旧表中插入值并将所有值插入到新的但最近创建的表中。旧表列出了发票编号,有时发票编号有重复。我需要我正在尝试创建的这个新列,称为invoice_id 到 AUTO_INCREMENT,当没有为将要插入的未来值插入值时,并允许在现有值和未来值上重复。当没有插入值时,需要auto_increment。
ID (primary) || invoice_ID (needs to auto_increment AND allow duplicates) || other colums
1 || 1
2 || 2
3 || 2
4 || 3
我尝试了一些命令,结果如下:
ALTER TABLE `invoices` ADD `invoice_ID` INT NOT NULL AUTO_INCREMENT AFTER `ID` ,
ADD PRIMARY KEY ( `facture` )
结果:
MySQL said:
#1075 - Incorrect table definition; there can be only one auto column and it must be
defined as a key
也试过了:
ALTER TABLE `invoices` ADD `invoice_ID` INT NOT NULL AUTO_INCREMENT AFTER `ID` ,
ADD KEY ( `invoice_ID` ) ,
ADD INDEX ( `invoice_ID` )
结果:
#1075 - Incorrect table definition; **there can be only one auto column** and it must
be defined as a key
我也尝试了一些不同的选项,比如当然不添加为主键,但似乎只要我添加 auto_increment 请求,它就会使我的查询成为“AS PRIMARY KEY”。
【问题讨论】:
标签: mysql phpmyadmin