The query below lists tables that are not referenced by foreign keys.
See also:
Query
select 'No FKs >-' foreign_keys,
schema_name(fk_tab.schema_id) as schema_name,
fk_tab.name as table_name
from sys.tables as fk_tab
left outer join sys.foreign_keys as 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
Columns
- foreign_keys - symbol indicating the lack of FK references
- schema_name - name of the schema
- table_name - name of the table
Rows
- One row: represents one table
- Scope of rows: all tables in a database that are not referenced by foreign keys
- Ordered by: schema, table name
Sample results
List of tables in the AdventureWorksLT that are not referenced by foreign keys: