Coder.Z
2018-01-16 09:28
采纳率: 40%
浏览 1.4k

mysql 分区后,修改主键,自增失效

我创建了一个表:
create table part(id int) partition by range(id)(partition p0 values less than (1), partition p1 values less than (2), partition p2 values less than (3), partition p3 values less than (4), partition pm values less than maxvalue);
然后插入数据:
insert into part values(0),(1),(2),(3),(4);
然后我想修改id字段的名字和约束:
alter table part change id code int not null;
这时收到一个错误:
(1054, u"Unknown column 'id' in 'partition function'")
所以我做了如下操作:
alter table part change id code int not null, add id int primary key auto_increment;
执行貌似成功,但是收到一个错误,结果如下:
Query OK, 0 rows affected
Time: 16.519s
(1065, u'Query was empty')
然后select查看part表:
select * from part;
结果却是这样:
+------+----+
| code | id |
+------+----+
| 0 | 1 |
| 1 | 1 |
| 2 | 1 |
| 3 | 1 |
| 4 | 1 |
+------+----+
5 rows in set
Time: 0.015s
求大神解释

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • devmiao 2018-01-16 14:25
    打赏 评论

相关推荐 更多相似问题