将新列添加到生产中的现有 table
Adding a new column to an existing table in production
当 table 包含一百万条记录并且它处于活动状态时,在生产 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、"Adding Columns with a Default Value"章节
当 table 包含一百万条记录并且它处于活动状态时,在生产 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、"Adding Columns with a Default Value"章节