Oracle 去掉联合主键中的一列

来源:互联网 发布:淘宝拒签退款邮费谁出 编辑:程序博客网 时间:2024/05/18 19:44

需求:现在有张表中是联合主键,但是现在要改成只有一个字段是主键。

解决方法:先删除这张表的联合主键,再重新创建这张表的主键,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);



原创粉丝点击