Database schema viewer: tables, keys and relationships
Before changing a table, check its columns, keys and relationships. A schema viewer makes that easier to see. Start with the database’s actual definitions, then use a diagram to understand how the tables fit together.
Inspect a PostgreSQL table’s structure
This query shows the columns in public.tasks. Change those names to the schema and table you want to inspect.
SELECT column_name, data_type, is_nullable, column_default
FROM information_schema.columns
WHERE table_schema = 'public' AND table_name = 'tasks'
ORDER BY ordinal_position;Then inspect its declared constraints:
SELECT constraint_name, constraint_type
FROM information_schema.table_constraints
WHERE table_schema = 'public' AND table_name = 'tasks'
ORDER BY constraint_type, constraint_name;The result can include primary keys, foreign keys, unique constraints and checks visible to your role. A column called user_id is not proof that a foreign key exists. Application code may enforce a relationship that the database does not declare.
Use the engine’s own metadata
For MySQL or MariaDB, SHOW CREATE TABLE tasks reveals the table definition in the selected database. For SQLite, read the SQL column in sqlite_schema or follow the tables and columns guide. PostgreSQL, MySQL and SQLite differ in their metadata and type systems; a generic diagram can hide those differences.
Read a relationship diagram carefully
Check which schema is included, whether the connection can see all relevant objects, and whether relationships are declared or inferred. Separate a conceptual model from the live database. A diagram exported last month may no longer describe today’s schema.
plainDB’s Mac edition includes ER diagrams and a table designer; consult the platform feature matrix before expecting those tools on Windows. For either platform, SQL metadata inspection remains useful when reviewing a migration.
Before changing structure
Record the existing definition, understand dependent queries, and test the migration against an isolated copy. A schema viewer helps you understand an object; it does not establish that dropping a column or changing a key is safe.
Reference: PostgreSQL information schema.