向原有表中添加不为空列(oracle为例)

3 篇文章 0 订阅

在学习工作中,我们会遇到向一些已经使用过程中的表中添加新字段,而且不允许为空。

这里以某个表为例:

alter table sys_org add (Is_bottom_gain  char(1)  null) ;
alter table sys_org add (Is_bottom_unit  char(1)  null) ;
alter table sys_org add (Belong_Financial_industry  varchar2(100)  null) ;
alter table sys_org add (Belong_profit_centre    varchar2(100)  null) ;
alter table sys_org add (Belong_Financial_org_cost    varchar2(100)  null) ;
alter table sys_org add (Belong_Financial_org_profit    varchar2(100)  null default '0') ;
alter table sys_org add (Account_org_name     varchar2(100)  null) ;

comment on column SYS_ORG.Is_bottom_gain
is '是否底层利润中心';
comment on column SYS_ORG.Is_bottom_unit
is '是否底层单位';
comment on column SYS_ORG.Belong_Financial_industry
is '财务所属行业';
comment on column SYS_ORG.Belong_profit_centre
is '所属利润中心';
comment on column SYS_ORG.Belong_Financial_org_cost
is '所属财务组织';
comment on column SYS_ORG.Belong_Financial_org_profit
is '所属财务组织';
comment on column SYS_ORG.Account_org_name
is '核算组织名称';



---------------------------我现在要新加两个不为空字段

alter table sys_org modify Is_bottom_gain  default '0';
alter table sys_org modify Is_bottom_unit  default '0';

ALTER TABLE sys_org MODIFY Is_bottom_gain not NULL;
ALTER TABLE sys_org MODIFY Is_bottom_unit not NULL;


直接设置not null 不可行。因为存在之前的数据。

所以这里可以先默认给他加上默认值 0;执行之后再重新设置这一列not null.


评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

hidetou

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值