• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
james1207

博客园    首页    新随笔    联系   管理    订阅  订阅

修改表增加字段默认值default

对个生产库的表增加1个字段.字段类型是INT型, 表数据有2千万条, alter table table_name add xxoo number(4) default  0 ;

因此 不仅要修改字典,还要刷新全部数据.

1) 在ALTER sql中有带缺省值,ORACLE会直接刷新全部的记录。
2) 在ALTER sql中没有带缺省值,ORACLE只会影响到后来的记录。

alter table table_name add xxoo number(4) default null;

Table altered
 
Executed in 0.062 seconds

带有default null 就可以了

 alter table table_name add xxoo number(4) default 0;
 
Table altered

Executed in 1.625 seconds

原来的话 要更新所有的行,会导致UNDO段占用

 

使用语句Alter table a add test number(10) default 0;更新一个大表中字段时,表有四个分区,数据达到几十亿行,增加一个字段竟然要几个小时的时间,修改语句加上Nologging ,怎么没有作用呢?去找是不是哪有锁了呢,使用语句 select * from dba_locks where lock_id1=33784;发现Session_id为14的一直在执行,那么他在执行什么呢!查询一下吧。

使用语句:

select a.sid,a.username,c.SQL_TEXT from v$session a, dba_locks b,v$sqlarea c
  where b.lock_id1=33784 and a.SID=b.session_id
   and a.SQL_ADDRESS=c.ADDRESS;

哦,原来他在Update Test 字段值为0.至此总结到,原来Alter之后做的竟然是Update,也明白了为什么Undo表空间会爆涨。去掉Default 0,呵呵,很快就OK了。

建议没有必要时慎用Default

posted @ 2013-09-27 19:12  Class Xman  阅读(442)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3