建自增列 必须是主键列,先建主键,才能建自增列
1.
create table t_payment(
id int not null comment 'ID',
com_id numeric not null comment '公司ID',
);
alter table t_payment
add primary key (id);
alter table t_payment modify id int auto_increment;
2.
create table t_payment
(
id int not null auto_increment comment 'ID',
com_id numeric not null comment '公司ID',
primary key(id)
);

本文详细解释了在数据库中创建自增列必须是主键列,并且介绍了如何通过两次ALTER TABLE命令实现这一操作,包括首先建立主键,然后修改列属性为自增。
2590

被折叠的 条评论
为什么被折叠?



