Oracle 去掉联合主键中的一列
原创
©著作权归作者所有:来自51CTO博客作者hoho_12的原创作品,请联系作者获取转载授权,否则将追究法律责任
需求:现在有张表中是联合主键,但是现在要改成只有一个字段是主键。
解决方法:先删除这张表的联合主键,再重新创建这张表的主键,sql测试脚本如下
--创建测试表
create table test_wxh(
t_id number(16) not null,
t_name varchar2(256),
t_my_id number(16) not null
)
--添加联合主键
alter table test_wxh
add constraint PK_test_wxh primary key (t_id, t_my_id);
--表中插入数据
select * from test_wxh for update
--去掉联合主键,再添加一个主键
ALTER TABLE test_wxh drop constraint PK_test_wxh;
--再添加一个主键
alter table test_wxh
add constraint PK_test_wxh primary key (t_id);