在高并发,高负载的情况下如何给表添加字段

在高并发,高负载的情况下如何给表添加字段,并设置default值?
参与6

4同行回答

静以致远静以致远数据库运维工程师汇通天下
Adding Table ColumnsTo add a column to an existing table, use the ALTER TABLE...ADD statement.The following statement alters the hr.admin_emp table to add a new column named bonus:ALTER TABLE hr.admin_emp      ADD (bonus NUMBER (7...显示全部
Adding Table Columns
To add a column to an existing table, use the ALTER TABLE...ADD statement.
The following statement alters the hr.admin_emp table to add a new column named bonus:
ALTER TABLE hr.admin_emp
      ADD (bonus NUMBER (7,2));
If a new column is added to a table, the column is initially NULL unless you specify the DEFAULT clause. When you specify a default value, the database immediately updates each row with the default value. Note that this can take some time, and that during the update, there is an exclusive DML lock on the table. For some types of tables (for example, tables without LOB columns), if you specify both a NOT NULL constraint and a default value, the database can optimize the column add operation and greatly reduce the amount of time that the table is locked for DML.
You can add a column with a NOT NULL constraint only if the table does not contain any rows, or you specify a default value.

意思就是如果添加的新列,没有指定not null,它默认的是null,这样当你指定了default值时,每一条记录
的默认值都会被更改,会占用大量的DML锁,所以效率很低
如果该列not null,且有默认值,在11g中不在需要存储这个默认在所有的记录中,该默认值单独保存在数据字典里,在使用时,在从数据字典中调用,从而减少了DDL操作的时间,也减少了空间的使用。收起
互联网服务 · 2015-08-13
浏览1206
liulei_oracleliulei_oracle数据库管理员lgcns china
这个新特性这棒 但是完全点 在PM时间做吧显示全部
这个新特性这棒 但是完全点 在PM时间做吧收起
系统集成 · 2015-08-28
浏览1159
wbkingwbking软件开发工程师恒生电子
对比发现11g在增加列之后,以前的数据dump出来的内容未有任何改变.也就是说:在10g中,我们增加一个列和默认值,会自动的增加到真实的数据中,而在11g中增加列和默认值并未真的加到11g的表中已经存在的数据中....显示全部
对比发现11g在增加列之后,以前的数据dump出来的内容未有任何改变.也就是说:在10g中,我们增加一个列和默认值,会自动的增加到真实的数据中,而在11g中增加列和默认值并未真的加到11g的表中已经存在的数据中.收起
金融其它 · 2015-08-27
浏览1144
lhrbestlhrbest数据库管理员外汇交易中心
11g不用考虑性能问题,10g下呢?有什么好的办法吗?显示全部
11g不用考虑性能问题,10g下呢?有什么好的办法吗?收起
互联网服务 · 2015-08-13
浏览1158

提问者

lhrbest
数据库管理员外汇交易中心
擅长领域: 服务器LinuxCentOS

相关问题

相关资料

相关文章

问题状态

  • 发布时间:2015-08-13
  • 关注会员:1 人
  • 问题浏览:2747
  • 最近回答:2015-08-28
  • X社区推广