[20141029]10g和11G檢視DBA_CONSTRAINTS
[20141029]10g和11G檢視DBA_CONSTRAINTS.txt
--上午同事講一下表從10g匯入11g時,一些約束沒有匯入,感覺不可能出現這種情況,我在10g下檢視一些約束的狀態是是disabled,但是
--type顯示的是問號(在toad下).想起來我以前遇到的問題,
--[20140131]toad看constraints的問題.txt
http://blog.itpub.net/267265/viewspace-1076597/
--很容易明白這些表是沒有主鍵,不過在11g下檢視檢視DBA_CONSTRAINTS確實沒有這些約束,檢視檢視定義才發現11g下DBA_CONSTRAINTS的
--定義發生了變化:
SYS@test> select text from dba_views where view_name='DBA_CONSTRAINTS';
TEXT
-------------------------------------------------------------------------------
select ou.name, oc.name,
decode(c.type#, 1, 'C', 2, 'P', 3, 'U',
4, 'R', 5, 'V', 6, 'O', 7,'C', 8, 'H', 9, 'F',
10, 'F', 11, 'F', 13, 'F', '?'),
o.name, c.condition, ru.name, rc.name,
decode(c.type#, 4,
decode(c.refact, 1, 'CASCADE', 2, 'SET NULL', 'NO ACTION'),
NULL),
decode(c.type#, 5, 'ENABLED',
decode(c.enabled, NULL, 'DISABLED', 'ENABLED')),
decode(bitand(c.defer, 1), 1, 'DEFERRABLE', 'NOT DEFERRABLE'),
decode(bitand(c.defer, 2), 2, 'DEFERRED', 'IMMEDIATE'),
decode(bitand(c.defer, 4), 4, 'VALIDATED', 'NOT VALIDATED'),
decode(bitand(c.defer, 8), 8, 'GENERATED NAME', 'USER NAME'),
decode(bitand(c.defer,16),16, 'BAD', null),
decode(bitand(c.defer,32),32, 'RELY', null),
c.mtime,
decode(c.type#, 2, ui.name, 3, ui.name, null),
decode(c.type#, 2, oi.name, 3, oi.name, null),
decode(bitand(c.defer, 256), 256,
decode(c.type#, 4,
case when (bitand(c.defer, 128) = 128
or o.status in (3, 5)
or ro.status in (3, 5)) then 'INVALID'
else null end,
case when (bitand(c.defer, 128) = 128
or o.status in (3, 5)) then 'INVALID'
else null end
),
null),
decode(bitand(c.defer, 256), 256, 'DEPEND ON VIEW', null)
from sys.con$ oc, sys.con$ rc, sys."_BASE_USER" ou, sys."_BASE_USER" ru,
sys."_CURRENT_EDITION_OBJ" ro, sys."_CURRENT_EDITION_OBJ" o, sys.cdef$ c,
sys.obj$ oi, sys.user$ ui
where oc.owner# = ou.user#
and oc.con# = c.con#
and c.obj# = o.obj#
and c.type# != 8 /* don't include hash expressions */
and (c.type# < 14 or c.type# > 17) /* don't include supplog cons */
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
and (c.type# != 12) /* don't include log group cons */
and c.rcon# = rc.con#(+)
and c.enabled = oi.obj#(+)
and oi.owner# = ui.user#(+)
and rc.owner# = ru.user#(+)
and c.robj# = ro.obj#(+)
--注意~的部分.(c.type# < 14 or c.type# > 17)不顯示.如果檢視10g的定義沒有這些部分.
$ grep -i 'cdef\$' * | grep -i 'create table cdef'
dcore.bsq:create table cdef$ /* constraint definition table */
create index i_cobj# on cluster c_cobj#
/
REM NOTE
REM Logminer/Streams uses contents of this table.
REM Please do not reuse any flags without verifying the impact of your
REM changes on inter-op.
create table cdef$ /* constraint definition table */
( con# number not null, /* constraint number */
obj# number not null, /* object number of base table/view */
cols number, /* number of columns in constraint */
type# number not null, /* constraint type: */
/* Note: If new types are added then please ensure that the */
/* {....}_CONSTRAINTS family of views reflect the new type. */
/* 1 = table check, 2 = primary key, 3 = unique, */
/* 4 = referential, 5 = view with CHECK OPTION, */
/* 6 = view READ ONLY check */
/* 7 - table check constraint associated with column NOT NULL */
/* 8 - hash expressions for hash clusters */
/* 9 - Scoped REF column constraint */
/* 10 - REF column WITH ROWID constraint */
/* 11 - REF/ADT column with NOT NULL const */
/* 12 - Log Groups for supplemental logging */
/* 13 - Allow PKref vals Storage in REF col */
/* 14 - Primary key supplemental logging */
/* 15 - Unique key supplemental logging */
/* 16 - Foreign key supplemental logging */
/* 17 - All column supplemental logging */
robj# number, /* object number of referenced table */
rcon# number, /* constraint number of referenced columns */
rrules varchar2(3), /* future: use this columns for pendant */
match# number, /* referential constraint match type: */
/* null = FULL, 1 = PARTIAL */
/* this column can also store information for other constraint types */
refact number, /* referential action: */
/* null = RESTRICT, 1 = CASCADE, 2 = SET NULL, 3 = SET DEFAULT */
enabled number, /* is constraint enabled? NULL if disabled */
condlength number, /* table check condition text length */
condition long, /* table check condition text */
intcols number, /* number of internal columns in constraint */
mtime date, /* date this constraint was last enabled-disabled */
defer number, /* 0x01 constraint is deferrable */
/* 0x02 constraint is deferred */
/* 0x04 constraint has been system validated */
/* 0x08 constraint name is system generated */
/* 0x10 constraint is BAD, depends on current century */
/* 0x20, optimizer should RELY on this constraint */
/* 0x40 Log Group ALWAYS option */
/* 0x80 (view related) constraint is invalid */
/* 0x100 constraint depends on a view */
/* 0x200 constraint is a partitioning constraint */
spare1 number, /* sql version flag: see kpul.h */
spare2 number, /* create/last modify constraint SCN wrap */
spare3 number, /* create/last modify constraint SCN base */
spare4 varchar2(1000),
pare5 varchar2(1000),
spare6 date
)
cluster c_cobj#(obj#)
/
--做一個簡單的測試:
SCOTT@test> @ver1
PORT_STRING VERSION BANNER
------------------------------ -------------- --------------------------------------------------------------------------------
x86_64/Linux 2.4.xx 11.2.0.3.0 Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
create table ttx
( a number(1) not null,
b number(1),
SUPPLEMENTAL LOG DATA (ALL) COLUMNS
);
SCOTT@test> select dbms_metadata.get_ddl('TABLE', 'TTX') from dual ;
DBMS_METADATA.GET_DDL('TABLE','TTX')
-----------------------------------------------------------------------
CREATE TABLE "SCOTT"."TTX"
( "A" NUMBER(1,0) NOT NULL ENABLE,
"B" NUMBER(1,0),
SUPPLEMENTAL LOG DATA (ALL) COLUMNS
) SEGMENT CREATION DEFERRED
PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255
NOCOMPRESS LOGGING
TABLESPACE "USERS" ;
SCOTT@test> select owner,CONSTRAINT_NAME from DBA_CONSTRAINTS where owner=user and table_name='TTX';
OWNER CONSTRAINT_NAME
------ ------------------------------
SCOTT SYS_C0042410
--可以發現僅僅有1個約束.
SELECT CON#,
OBJ#,
COLS,
TYPE#,
ROBJ#,
RCON#,
RRULES,
MATCH#,
REFACT,
ENABLED,
CONDLENGTH,
CONDITION
FROM sys.cdef$
WHERE obj# IN (SELECT object_id
FROM dba_objects
WHERE object_name = 'TTX' AND owner = USER);
CON# OBJ# COLS TYPE# ROBJ# RCON# RRU MATCH# REFACT ENABLED CONDLENGTH CONDITION
----- ---------- ---------- ---------- ---------- ---------- --- ---------- ---------- ---------- ---------- -----------------
42410 292348 1 7 1 15 "A" IS NOT NULL
42411 292348 0 17
-- 可以發現實際上有2個的,type#=17的在DBA_CONSTRAINTS檢視就不顯示了.
SCOTT@test> alter table ttx drop supplemental log data (all) columns;
Table altered.
SCOTT@test> select dbms_metadata.get_ddl('TABLE', 'TTX') from dual ;
DBMS_METADATA.GET_DDL('TABLE','TTX')
----------------------------------------------------------------------------
CREATE TABLE "SCOTT"."TTX"
( "A" NUMBER(1,0) NOT NULL ENABLE,
"B" NUMBER(1,0)
) SEGMENT CREATION DEFERRED
PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255
NOCOMPRESS LOGGING
TABLESPACE "USERS" ;
SELECT CON#,
OBJ#,
COLS,
TYPE#,
ROBJ#,
RCON#,
RRULES,
MATCH#,
REFACT,
ENABLED,
CONDLENGTH,
CONDITION
FROM sys.cdef$
WHERE obj# IN (SELECT object_id
FROM dba_objects
WHERE object_name = 'TTX' AND owner = USER);
CON# OBJ# COLS TYPE# ROBJ# RCON# RRU MATCH# REFACT ENABLED CONDLENGTH CONDITION
----- ---------- ---------- ---------- ---------- ---------- --- ---------- ---------- ---------- ---------- ----------------------------------------
42410 292348 1 7 1 15 "A" IS NOT NULL
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/267265/viewspace-1313811/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 10g 11g 檢視是否DISABLE CRS和10g 11g LOCAL listener的區別
- 在10g/11g中如何檢視SQL Profiles資訊SQL
- oracle 10g 常用檢視Oracle 10g
- 10G開始Oracle區分物化檢視和表Oracle
- Oracle 11g系列:檢視Oracle
- Oracle 11g 建立物化檢視Oracle
- 10g 動態效能檢視[final]
- 11g警告檔案的檢視
- Oracle 11g 系統自帶任務的檢視和更改Oracle
- Oracle 常用效能檢視一覽表(10g)Oracle
- oracle 11g檢視alert日誌方法Oracle
- Oracle 11g 檢視監聽日誌Oracle
- 11G訪問DBA_OBJECTS和V$LOCK檢視時HANG住Object
- 10G物化檢視PCT快速重新整理不再需要物化檢視日誌(三)
- 10G物化檢視PCT快速重新整理不再需要物化檢視日誌(二)
- 10G物化檢視PCT快速重新整理不再需要物化檢視日誌(一)
- 普通檢視和物化檢視的區別
- 統計資訊10G和11G區別
- Oracle 10g 新增的dba_tab_modifications檢視Oracle 10g
- Oracle普通檢視和物化檢視的區別Oracle
- day04-檢視和檢視解析器
- Django檢視之檢視類和中介軟體Django
- oracle 11g 統計資訊 相關檢視Oracle
- 11g 日誌目錄查詢檢視
- Oracle 11g AWR 系列六:使用 AWR 檢視Oracle
- Animator視窗檢視Project檢視PlayerIdleAnimation和PlayerWalkingAnimationProject
- django 的類檢視和函式檢視-雜談Django函式
- Spring 檢視和檢視解析器簡介Spring
- v$sql檢視和v$sqlarea檢視的構建SQL
- Oracle 11g RAC檢視ASM日誌、grid日誌和DB日誌OracleASM
- oracle 10g 命令檢視錶空間大小情況Oracle 10g
- iOS10 UI教程檢視的繪製與檢視控制器和檢視iOSUI
- Django的檢視和模板Django
- JavaScript 檢視全文和收起JavaScript
- mysql建立索引和檢視MySql索引
- Flask URL和檢視(一)Flask
- 10g和11g自動任務的區別
- 10g和11g自動統計的區別