Home > Database > Oracle > body text

How to query the foreign keys of a table in Oracle

青灯夜游
Release: 2022-03-17 14:48:25
Original
9302 people have browsed it

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 = 要查询的表;
Copy after login

Query the column name of the foreign key constraint

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

Query the column name of the key of the reference table

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

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template