Oracle添加主键,删除主键,添加列,修改列,删除列及修改表名

目录

1、添加主键

2、删除主键

3、添加列 

4、修改列

5、删除列

6、修改表名


1、添加主键

有主键名:

alter table test(test表名) add constraint pk_test(pk_test为主键名) primary key(主键1,主键2,...)

无主键名: 

alter table test(test为表名) add primary key(主键1,主键2,...)

2、删除主键

有主键名:

alter table test(test为表名) drop constraint pk_test(pk_test为主键名)

无主键名:

--找到主键名
select * from user_cons_columns o where o.table_name = 'test' and o.position is not null;
--删除主键
alter table test(test为表名) drop constraint 主键名;

3、添加列 

alter table test(test为表名) add 字段名 字段类型(类型长度);
--举例
alter table test add name varchar2(10);

--添加字段注释
comment on column 表名.字段名 is '注释';
--举例
comment on column test.name is '姓名';

4、修改列

--修改列名
alter table test(test为表名) rename column 旧字段名 to 新字段名

--修改字段类型/字段长度 
alter table test(test为表名) modify 字段名称 字段类型(字段长度);

5、删除列

alter table test(test为表名) drop column 字段名;

6、修改表名

alter table 旧表名 rename to 新表名

--添加表注释
commment on table test(test为表名) is '注释';

 如有错误,评论区请指正

  • 1
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值