PostgreSQL: SQL script to get a list of all tables that has a particular column as foreign key

前端 未结 9 948
独厮守ぢ
独厮守ぢ 2021-01-29 23:31

I\'m using PostgreSQL and I\'m trying to list all the tables that have a particular column from a table as a foreign-key/reference. Can this be done? I\'m sure this information

9条回答
  •  迷失自我
    2021-01-30 00:09

    If you use the psql client, you can simply issue the \d table_name command to see which tables reference the given table. From the linked documentation page:

    \d[S+] [ pattern ]

    For each relation (table, view, materialized view, index, sequence, or foreign table) or composite type matching the pattern, show all columns, their types, the tablespace (if not the default) and any special attributes such as NOT NULL or defaults. Associated indexes, constraints, rules, and triggers are also shown. For foreign tables, the associated foreign server is shown as well.

提交回复
热议问题