Chinaunix首页 | 论坛 | 博客
  • 博客访问: 539972
  • 博文数量: 128
  • 博客积分: 4000
  • 博客等级: 上校
  • 技术积分: 1345
  • 用 户 组: 普通用户
  • 注册时间: 2008-01-22 21:43
文章分类

全部博文(128)

文章存档

2009年(30)

2008年(98)

我的朋友

分类: Oracle

2008-09-24 15:43:59

今天想truncate一张表,但报ORA-02266错误
想到可能是主键被子表引用,查了一下
解决如下:
SQL> truncate table area;
truncate table area
               *
ERROR 位于第 1 行:
ORA-02266: 表中的唯一/主键被启用的外部关键字引用


SQL> alter table area disable primary key cascade;

表已更改。

SQL> truncate table area;

表已截掉。

SQL> alter table area enable primary key;

表已更改。

SQL>


继续深查一下关于外键的引用
select c1.table_name,
       c1.constraint_name,
       dcc1.column_name,
       c2.table_name,
       c2.constraint_name,
       dcc2.column_name
from dba_constraints c1,
     dba_constraints c2,
     dba_cons_columns dcc1,
     dba_cons_columns dcc2
where c1.owner = 'RM'
  and c1.table_name = 'AREA'
  and dcc1.constraint_name = c1.constraint_name
  and dcc1.owner = c1.owner
  and c2.constraint_type = 'R'
  and c2.r_constraint_name = c1.constraint_name
  and dcc2.owner = c2.owner
  and dcc2.constraint_name = c2.constraint_name;

TABLE_NAME CONSTRAINT_NAME COLUMN_NAME TABLE_NAME            CONSTRAINT_NAME                COLUMN_NAME
---------- --------------- ----------- --------------------- ------------------------------ -----------
AREA       PK_AREA         AREA_ID     PHONE_NUMBER          REF_1026                       AREA_ID
AREA       PK_AREA         AREA_ID     PHONE_NUMBER_POOL     REF_1141                       AREA_ID
AREA       PK_AREA         AREA_ID     PHYSICAL_RESOURCE     REF_1214                       AREA_ID
AREA       PK_AREA         AREA_ID     PNE_GROUP             REF_1029                       AREA_ID
AREA       PK_AREA         AREA_ID     PN_LEVEL_GROUP        FK_PN_LEVEL_REFERENCE_AREA     AREA_ID
AREA       PK_AREA         AREA_ID     PORT_GROUP            FK_PORT_GRO_REFERENCE_AREA     AREA_ID
AREA       PK_AREA         AREA_ID     POSTAL_CODE           REF_648                        AREA_ID
AREA       PK_AREA         AREA_ID     MANAGED_PORT          REF_1035                       AREA_ID
AREA       PK_AREA         AREA_ID     NUMBER_ELEMENT        REF_1027                       AREA_ID
AREA       PK_AREA         AREA_ID     COMP_RSC              FK_COMP_RSC_REFERENCE_AREA     AREA_ID
AREA       PK_AREA         AREA_ID     RSC_CODE_RULE_DEL     REF_1186                       AREA_ID
AREA       PK_AREA         AREA_ID     RSC_DYNAMIC_COND      FRI_AREA_ID                    AREA_ID
AREA       PK_AREA         AREA_ID     DEVICE_SIDE_PORT      REF_1034                       AREA_ID
AREA       PK_AREA         AREA_ID     EQUIPMENT             REF_1039                       AREA_ID
AREA       PK_AREA         AREA_ID     EXPRESSION_VARIABLE   REF_1190                       AREA_ID
AREA       PK_AREA         AREA_ID     REGIONAL_LOC          REF_640                        AREA_ID
AREA       PK_AREA         AREA_ID     REGIONAL_LOC_ALIAS    REF_644                        AREA_ID
AREA       PK_AREA         AREA_ID     RESOURCE_FACING_SERV  REF_446                        AREA_ID
AREA       PK_AREA         AREA_ID     RSC_RULE_SCENE        FK_RSC_RULE_REFERENCE_AREA     AREA_ID
AREA       PK_AREA         AREA_ID     RSC_STATUS_MIGRATION  REF_1201                       AREA_ID
 
TABLE_NAME CONSTRAINT_NAME COLUMN_NAME TABLE_NAME            CONSTRAINT_NAME                COLUMN_NAME
---------- --------------- ----------- --------------------- ------------------------------ -----------
AREA       PK_AREA         AREA_ID     TERMINAL_DEVICE       REF_1168                       AREA_ID
AREA       PK_AREA         AREA_ID     TML                   REF_630                        AREA_ID
AREA       PK_AREA         AREA_ID     URI                   REF_1226                       AREA_ID
AREA       PK_AREA         AREA_ID     USER_SIDE_PORT        REF_1043                       AREA_ID
AREA       PK_AREA         AREA_ID     VIRTUAL_ADDRESS       REF_675                        AREA_ID
AREA       PK_AREA         AREA_ID     VIRTUAL_NUMBER        REF_1041                       AREA_ID
AREA       PK_AREA         AREA_ID     TSM_ROUTER            FK_TSM_ROUT_REF_AREA           AREA_ID
AREA       PK_AREA         AREA_ID     ACCESS_ACCOUNT        REF_1021                       AREA_ID
AREA       PK_AREA         AREA_ID     ACCESS_NUMBER         REF_1215                       AREA_ID
AREA       PK_AREA         AREA_ID     ADDR_LOC              REF_624                        AREA_ID
AREA       PK_AREA         AREA_ID     AN_CODE_RULE          REF_1230                       AREA_ID
AREA       PK_AREA         AREA_ID     AN_STATUS_MIGRATION   REF_1202                       AREA_ID
AREA       PK_AREA         AREA_ID     AREA_2_POOL           FK_AREA_2_P_REFERENCE_AREA     AREA_ID
AREA       PK_AREA         AREA_ID     AREA_2_TML            FK_AREA_2_T_REFERENCE_AREA     AREA_ID
AREA       PK_AREA         AREA_ID     DEVICE                REF_1067                       AREA_ID
AREA       PK_AREA         AREA_ID     DEVICE_INSIDE_JUMP    REF_1037                       AREA_ID
AREA       PK_AREA         AREA_ID     DEVICE_NUMBER         REF_1150                       AREA_ID
AREA       PK_AREA         AREA_ID     CONNECTOR             REF_1032                       AREA_ID
 
38 rows selected
阅读(3990) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~