Home >Database >Oracle >How to query the foreign keys of a table in Oracle

How to query the foreign keys of a table in Oracle

青灯夜游
青灯夜游Original
2022-03-17 14:48:259312browse

In Oracle, you can use the select statement to query the foreign key of the table, the syntax is "select * from user_cons_columns cl where cl.constraint_name = foreign key name;".

How to query the foreign keys of a table in Oracle

The operating environment of this tutorial: Windows 7 system, Oracle 11g version, Dell G3 computer.

Foreign key is the relationship between tables. For example, an instance of one table refers to a column of another table. Let's start with a simple example to understand the concept clearly.

Query the foreign key of the table (including the name, the table name of the reference table and the corresponding key name, the following is a multi-step query)

Query table information

select * from user_constraints c where c.constraint_type = 'R' and c.table_name = 要查询的表;

Query the column name of the foreign key constraint

select * from user_cons_columns cl where cl.constraint_name = 外键名称;

Query the column name of the key of the reference table

select * from user_cons_columns cl where cl.constraint_name = 外键引用表的键名;

Recommended tutorial: "Oracle Tutorial"

The above is the detailed content of How to query the foreign keys of a table in Oracle. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn