OB支持类似MySQL的ALTER TABLE ... ADD PRIMARY KEY语法吗

【 使用环境 】测试环境
【 OB or 其他组件 】
【 使用版本 】Server version: 5.7.25 OceanBase 3.1.4 (r10000092022071511-b4bfa011ceaef428782dcb65ae89190c40b78c2f) (Built Jul 15 2022 11:45:14)
【问题描述】建表后想再添加主键定义失败
【复现路径】
【问题现象及影响】
【附件】

# 先建表
obclient [test]> create table t1(id int, c1 int);
Query OK, 0 rows affected (0.159 sec)

# 再添加主键失败
obclient [test]> alter table t1 add primary key(id);
ERROR 1235 (0A000): Not supported feature or function

# 参考OB手册,用modify和change语法也失败
obclient [test]> alter table t1 modify id int primary key;
ERROR 1235 (0A000): Not supported feature or function
obclient [test]> alter table t1 modify id int auto_increment primary key;
ERROR 1235 (0A000): Not supported feature or function
obclient [test]> alter table t1 modify id int not null auto_increment primary key;
ERROR 1235 (0A000): Not supported feature or function
obclient [test]> alter table t1 modify id int not null primary key;
ERROR 1235 (0A000): Not supported feature or function
obclient [test]> alter table t1 change id id int not null primary key;
ERROR 1235 (0A000): Not supported feature or function

文档中没有相关案例,只好来提问了,谢谢。

参考文档: ALTER TABLE-OceanBase 数据库-OceanBase文档中心-分布式数据库使用文档

1 个赞

3.x版本还不支持加主键,要到4.0才支持

可以参考一下这个文档,有列出支持的DDL操作:https://www.oceanbase.com/docs/community-observer-cn-10000000000450633