I've seen a ton of queries to list primary and foreign keys but how can I query for tables missing primary and foreign keys?
PostgreSQL 8.4 and 9.x versions
I've seen a ton of queries to list primary and foreign keys but how can I query for tables missing primary and foreign keys? PostgreSQL 8.4 and 9.x versions |
|||
|
To list all tables without a primary key, you can use this:
It's not clear to me if you want to find tables that are not referencing any other tables or tables that are not referenced by other tables. But both things can be obtained by querying |
||||
|
Another one query to get all tables without primary keys:
Unfortunately PostgreSQL has no idea what tables are supposed to have FKs. So it is manual work, you will need to look over all the tables and find such tables by yourself. |
|||
|