Is there a way using SQL to list all foreign keys for a given table? I know the table name / schema and I can plug that in.
相关问题
- SQL join to get the cartesian product of 2 columns
- sql execution latency when assign to a variable
- Difference between Types.INTEGER and Types.NULL in
- php PDO::FETCH_ASSOC doesnt detect select after ba
- Bulk update SQL Server C#
Note: Do not forget column's order while reading constraint columns!
Proper solution to the problem, using
information_schema
, working with multi column keys, joining columns of different names in both tables correctly and also compatible with ms sqlsever:Note: There are some differences between potgresql and sqlserver implementations of
information_schema
which make the top answer give different results on the two systems - one shows column names for the foreign key table the other for the primary key table. For this reason I decided to use KEY_COLUMN_USAGE view instead.Issue
\d+ tablename
on PostgreSQL prompt, in addition to showing table column's data types it'll show the indexes and foreign keys.