0

我们知道 PK 和 FKs 类型必须相同,Oracle 中的大小可以不同

  1. 找到所有的外键,
  2. 找到它们所引用的所有 PK
  3. 比较长度
  4. 如果 FK 很短,则使用 PK 的长度作为标准。

有人拿到剧本了吗?

4

2 回答 2

0

你可以试试这个(检查一个模式):

select mcols.table_name , mcols.column_name, mcols.data_type, mcols.data_length, mcols.data_precision, mcols.data_scale, dcols.table_name, dcols.column_name, dcols.data_length, dcols.data_precision, dcols.data_scale
from user_tab_cols mcols, user_cons_columns mc, user_constraints dt, user_cons_columns dc, user_tab_cols dcols
where dt.constraint_type = 'R'  -- Referential constraints, i.e. foreign keys
and dt.r_constraint_name = mc.constraint_name
and dc.constraint_name = dt.constraint_name
and mc.position = dc.position
and mcols.table_name = mc.table_name
and mcols.column_name = mc.column_name
and dcols.table_name = dc.table_name
and dcols.column_name = dc.column_name
-- Filter to list only columns that differ
and (mcols.data_type <> dcols.data_type      -- Check for CHAR vs VARCHAR2
  or mcols.data_length <> dcols.data_length  -- Check length (for varchar columns)
  or nvl(mcols.data_precision, 0) <> nvl(dcols.data_precision, 0) -- Check precision (for number columns)
  or nvl(mcols.data_scale, 0) <> nvl(dcols.data_scale, 0)  -- Check scale (for number columns)
);
;
于 2012-09-10T13:49:53.743 回答
0
SELECT cc.table_name,
       CC.COLUMN_NAME,
       TCF.DATA_TYPE || '(' || TCF.DATA_PRECISION || ',' || TCF.DATA_SCALE || ')' DTYPE1,
       rcc.table_name AS r_table_name,
       RCC.COLUMN_NAME AS R_COLUMN_NAME,
       TCP.DATA_TYPE || '(' || TCP.DATA_PRECISION || ',' || TCP.DATA_SCALE || ')' DTYPE2,
       cc.position
FROM   user_constraints c
       JOIN user_cons_columns cc ON c.owner = cc.owner AND c.constraint_name = cc.constraint_name
       JOIN USER_CONS_COLUMNS RCC ON C.OWNER = RCC.OWNER AND C.R_CONSTRAINT_NAME = RCC.CONSTRAINT_NAME AND CC.POSITION = RCC.POSITION
       JOIN USER_TAB_COLS TCF ON TCF.TABLE_NAME = CC.TABLE_NAME AND TCF.COLUMN_NAME = CC.COLUMN_NAME
       JOIN USER_TAB_COLS TCP ON TCP.TABLE_NAME = RCC.TABLE_NAME AND TCP.COLUMN_NAME = RCC.COLUMN_NAME
WHERE TCF.DATA_TYPE || '(' || TCF.DATA_PRECISION || ',' || TCF.DATA_SCALE || ')' != TCP.DATA_TYPE || '(' || TCP.DATA_PRECISION || ',' || TCP.DATA_SCALE || ')'
ORDER BY c.constraint_name, cc.table_name, cc.position;
于 2012-09-10T16:15:18.263 回答