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

前端 未结 9 1066
独厮守ぢ
独厮守ぢ 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-29 23:56

    A simple request for recovered the names of foreign key as well as the names of the tables:

    SELECT CONSTRAINT_NAME, table_name
    FROM
       information_schema.table_constraints 
    WHERE table_schema='public' and constraint_type='FOREIGN KEY'
    

提交回复
热议问题