Query below lists tables that are not referenced by the foreign keys.
- Tables that are not referenced by the foreign keys ,
- Loner Tables - tables without relationships,
- Summary article of FK queries for SQL Server.
select 'No FKs >-' foreign_keys, schema_name(fk_tab.schema_id) as schema_name, fk_tab.name as table_name from sys.tables fk_tab left outer join sys.foreign_keys fk on fk_tab.object_id = fk.referenced_object_id where fk.object_id is null order by schema_name(fk_tab.schema_id), fk_tab.name
- foreign_keys - symbol indicating lack of FK references
- schema_name - table schema name
- table_name - table name
- One row represents one table
- Scope of rows: all tables in a database that are not referenced by the foreign keys
- Ordered by schema, table name
List of tables in AdventureWorks not referenced by foreign keys: