Get the App
SLTechnology News&Howtos  ›  Database  › 

How does Oracle find out which table the foreign key is built on?

Shulou Source: shulou.com Published: 2022-06-01 10:36:00 10月03日 Update

How to find out which table the foreign key is built on

Sometimes when deleting a table record, it will report an error that the foreign key constraint cannot be deleted.

If you do not understand the relationship between tables, you can query the table on which the foreign key is built by using the following statement:

Select * from dba_constraints where constraint_name='xxx' and constraint_type ='R'

For example, the following error is reported in my program log. I want to know which table the foreign key is on.

2015-09-08 18:28:18 [main:261597003]-[ERROR] java.sql.SQLException: ORA-02291: violation of complete constraint (IRP.FK66EC57AF5158B9FB)-parent keyword not found

Select * from dba_constraints where constraint_name='FK66EC57AF5158B9FB' and constraint_type ='R'

For example:

Execution of delete from tablename Times error:

ORA-02292: integrity constraint (CCSYS.FK_T_BME_TASKRUNRESULT_TASKID) violated-child record found

You can do this by executing

Select table_name from dba_constraints where constraint_name='FK_T_BME_TASKRUNRESULT_TASKID' and constraint_type ='R'

Query that the foreign key is built on the T_BME_TASKRUNRESULT table, delete the t_bme_task table first, and then delete the TASKRUNSULT table record.

Tags: Can pass query report between key keyword I want log time Times is in sometimes condition program solve table statement error will report Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux Shulou Information Docker Redmi Shulou Tech Info