当该表包含一百万条记录并且处于事件状态时,在生产 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/