The query below lists tables that are not referenced by foreign keys.
select 'No FKs >-' as foreign_keys, tab.table_schema as database_name, tab.table_name from information_schema.tables tab left join information_schema.referential_constraints ref on ref.unique_constraint_schema = tab.table_schema and ref.referenced_table_name = tab.table_name where tab.table_type = 'BASE TABLE' and tab.table_schema not in ('mysql', 'information_schema', 'performance_schema', 'sys') and ref.constraint_name is null -- and tab.table_schema = 'your database name' order by tab.table_schema, tab.table_name;
Note: if you need the information for a specific database (schema), then uncomment the table_schema line and provide your database name.
- foreign_keys - symbol indicating the lack of FK references
- database_name - name of the database (schema)
- table_name - name of the table
- One row: represents one table
- Scope of rows: all tables in a database (schema) that are not referenced by foreign keys
- Ordered by: database name and table name