加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Oracle 去掉联合主键中的一列

发布时间:2020-12-12 14:10:41 所属栏目:百科 来源:网络整理
导读:需求:现在有张表中是联合主键,但是现在要改成只有一个字段是主键。 解决方法:先删除这张表的联合主键,再重新创建这张表的主键,sql测试脚本如下 --创建测试表create table test_wxh( t_id number(16) not null,t_name varchar2(256),t_my_id number(16)

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

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读