如题,我现在建一张表,其中我要一个流水ID,我想他自动增长,我的表还有一个ID做主键,为什么自增列会报错,自增列只能是主键吗,我设置了唯一索引也不行
mysql 5.5以后可以
CREATE TABLE `test` (
`testID` int(11) NOT NULL,
`string` varchar(45) DEFAULT NULL,
`testInc` int(11) NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`testID`),
KEY `testInc` (`testInc`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;
insert into test(
testID,
string
)
values (
1,
'Hello'
);
insert into test(
testID,
string
)
values (
2,
'world'
);
字段类型设置成int类型的
明显不行了。。。。。。。。。。。。。。。。
你把testInc设置为主键自动递增了而不是你在问题中描述的testID。