oracle - 向生产中的现有表添加新列

标签 oracle alter

当该表包含一百万条记录并且处于事件状态时,在生产 Oracle 数据库中添加具有默认值的非空列的最佳方法是什么。如果我们在单个语句中创建列、添加默认值并使其不为空,它会创建任何锁吗?

最佳答案

取决于版本。从11g开始,你可以执行一个简单的ALTER TABLE命令,不会有任何影响,默认值没有具体化,取自字典信息。

alter table tablename add columnname varchar2(2) default 'XX' not null;

The above statement will not issue an update to all the records of the table [...] When a user selects the column for an existing record, Oracle gets the fact about the default value from the data dictionary [...] and still not incur any penalty for redo and undo generation [...]

Source here ,“添加具有默认值的列”章节

关于oracle - 向生产中的现有表添加新列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53016072/

相关文章:

sql - 如何修复 SQL Developer Data Modeller 中的 "ERROR: FK name length exceeds maximum allowed length(30)"

java - 迭代 ResultSet 时更新行需要花费大量时间

javascript - Node.js + OracleDB : ORA-01036: illegal variable name/number

mysql alter table 会锁表吗?

mysql - 在mysql中重命名名为 "add"的列

mysql - 从 mysql 列中删除枚举值

mysql - 如何使用从 case 语句派生的列更新 View ?

mysql - innodb_online_alter_log_max_size 是否从内存或硬盘中获取内存

sql - 删除约束时出现错误消息

oracle - SQL避免在select语句中调用同一个函数两次