create table进阶学习系列(七)
本篇学习create table子项:supplemental_logging_props
supplemental_logging_props子项组成如下:
{ supplemental_log_grp_clause
| supplemental_id_key_clause
}
supplemental_log_grp_clause子句
GROUP log_group
(column [ NO LOG ]
[, column [ NO LOG ] ]...)
[ ALWAYS ]
supplemental_id_key_clause子句
DATA
({ ALL
| PRIMARY KEY
| UNIQUE
| FOREIGN KEY
}
[, { ALL
| PRIMARY KEY
| UNIQUE
| FOREIGN KEY
}
]...
)
COLUMNS
先测试 supplemental_log_grp_clause子句
ALL_LOG_GROUPS
--此视图查询当前数据库的日志组定义的相关信息
ALL_LOG_GROUPS describes the log group definitions on the tables accessible to the current user.
SQL> r
1* select log_group_name,table_name,column_name,position,logging_property from
dba_log_group_columns
LOG_GROUP_NAME TABLE_NAME COLUMN_NAM POSITION LOGGING_PROP
-------------------- -------------------- ---------- ---------- ------------
ENC$_LOG_GRP ENC$ OBJ# 1 LOG
ENC$_LOG_GRP ENC$ OWNER# 2 LOG
---如下为supplemental_logging_props语义
supplemental_logging_props
---记录额外日志为了支持基于日志的工具
The supplemental_logging_props clause lets you instruct the database to put additional data into the log stream to support log-based tools.
supplemental_log_grp_clause Use this clause to create a named log group.
?
The NO LOG clause lets you omit from the redo log one or more columns that would otherwise be included in the redo for the named log group. You must specify at least one fixed-length column without NO LOG in the named log group.
?
If you specify ALWAYS, then during an update, the database includes in the redo all columns in the log group. This is called an unconditional log group (sometimes called an "always log group"), because Oracle Database supplementally logs all the columns in the log group when the associated row is modified. If you omit ALWAYS, then the database supplementally logs all the columns in the log group only if any column in the log group is modified. This is called a conditional log group.
You can query the appropriate USER_, ALL_, or DBA_LOG_GROUP_COLUMNS data dictionary view to determine whether any supplemental logging has already been specified.
---第一种语法创建一直报错,
SQL> create table t_constraint_table(a int) group lgrp always;
create table t_constraint_table(a int) group lgrp always
*
ERROR at line 1:
ORA-00922: missing or invalid option
--查询网络,采用alter table运行成功
SQL> alter table t_log add supplemental log group log_grp(a) always;
Table altered.
SQL>
---上述添加的信息已经体现出来,log_grp日志组,它用于表t_log
SQL> select log_group_name,table_name,column_name,position,logging_property from
2 dba_log_group_columns
3 ;
LOG_GROUP_NAME TABLE_NAME COLUMN_NAME POSITION LOGGING_PROPERTY
------------------------------ ------------------------------ -------------------------------------------------------------------------------- ---------- ----------------
ENC$_LOG_GRP ENC$ OBJ# 1 LOG
ENC$_LOG_GRP ENC$ OWNER# 2 LOG
LOG_GRP T_LOG A 1 LOG
--日志组信息
SQL> select * from dba_log_groups;
OWNER LOG_GROUP_NAME TABLE_NAME LOG_GROUP_TYPE ALWAYS GENERATED
------------------------------ ------------------------------ ------------------------------ ------------------- ----------- --------------
SYS ENC$_LOG_GRP ENC$ USER LOG GROUP ALWAYS USER NAME
SCOTT LOG_GRP T_LOG USER LOG GROUP ALWAYS USER NAME
--删除表的附加日志记录功能
SQL> alter table t_log drop supplemental log group log_grp;
Table altered
---必须要在日志组中指定一个表列开启日志记录功能,否则报错
SQL> alter table t_log add supplemental log group log_grp (a no log) always;
alter table t_log add supplemental log group log_grp (a no log) always
ORA-32592: all columns in log group can not be no log columns
SQL> alter table t_log add supplemental log group log_grp (a,b no log) always;
Table altered
---第二种语法 supplemental_id_key_clause子句
SQL> alter table t_log add supplemental log data (all) columns;
Table altered
SQL> alter table t_log drop supplemental log data(all) columns;
Table altered
SQL> alter table t_log add supplemental log data (primary key) columns;
Table altered
SQL> alter table t_log drop supplemental log data(all) columns;
alter table t_log drop supplemental log data(all) columns
ORA-32587: Cannot drop nonexistent all column supplemental logging
SQL> alter table t_log drop supplemental log data(primary key) columns;
Table altered
SQL> alter table t_log add supplemental log data (unique) columns;
Table altered
SQL> alter table t_log drop supplemental log data(unique) columns;
Table altered
SQL> alter table t_log add supplemental log data (foreign) columns;
alter table t_log add supplemental log data (foreign) columns
ORA-00905: missing keyword
SQL> alter table t_log add supplemental log data (foreign key) columns;
Table altered
SQL> alter table t_log drop supplemental log data(foreign key) columns;
Table altered
SQL> alter table t_log add supplemental log data (all primary key) columns;
alter table t_log add supplemental log data (all primary key) columns
ORA-00907: missing right parenthesis
SQL> alter table t_log add supplemental log data (all,primary key) columns;
Table altered
SQL> alter table t_log drop supplemental log data (all,primary key) columns;
Table altered
---第二种语法的语义
--可指定all,primary key,unique,foreign key的单项或组合或全部
supplemental_id_key_clause Use this clause to specify that all or a combination of the primary key, unique key, and foreign key columns should be supplementally logged. Oracle Database will generate either an unconditional log group or a conditional log group. With an unconditional log group, the database supplementally logs all the columns in the log group when the associated row is modified. With a conditional log group, the database supplementally logs all the columns in the log group only if any column in the log group is modified.
---如下为各选项含义
---all columns为无条件式,由系统生成的日志组;
If you specify ALL COLUMNS, then the database includes in the redo log all the fixed-length maximum size columns of that row. Such a redo log is a system-generated unconditional log group.
---primary key,用于附有主键的表;一旦表更新,则记录表主键所有列相关信息
If you specify PRIMARY KEY COLUMNS, then for all tables with a primary key, the database places into the redo log all columns of the primary key whenever an update
----数据库评估记录哪些列的原则如下
is performed. Oracle Database evaluates which columns to supplementally log as follows:
--首先选取主键约束所属列(即引约束处于验证或标记不rely,且未标记为disabled或initially deferred)
First the database chooses columns of the primary key constraint, if the constraint is validated or marked RELY and is not marked as DISABLED or INITIALLY DEFERRED.
--如主键列不存在,数据库会选取最小的非空值且为唯一索引的列;
If no primary key columns exist, then the database looks for the smallest UNIQUE index with at least one NOT NULL column and uses the columns in that index.
--如上述两条件皆不满足,数据库记录表中所有的标量列
If no such index exists, then the database supplementally logs all scalar columns of the table.
---unique columns,面向唯一键或位图索引的列,此为有条件式的系统产生的日志组
If you specify UNIQUE COLUMNS, then for all tables with a unique key or a bitmap index, if any of the unique key or bitmap index columns are modified, the database
places into the redo log all other columns belonging to the unique key or bitmap index. Such a log group is a system-generated conditional log group.
--foreign key,面向外键所属表.如外键列修改,数据库则记录属于此外键的其它所有列的信息;
If you specify FOREIGN KEY COLUMNS, then for all tables with a foreign key, if any foreign key columns are modified, the database places into the redo log all
other columns belonging to the foreign key. Such a redo log is a system-generated conditional log group.
---如你指定多次此子句,数据库会创建多个独立的日志组
If you specify this clause multiple times, then the database creates a separate log group for each specification. You can query the appropriate USER_, ALL_,
or DBA_LOG_GROUPS data dictionary view to determine whether any supplemental logging data has already been specified.
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/9240380/viewspace-753074/
,如需转载,请注明出处,否则将追究法律责任。