Skip to content

Instantly share code, notes, and snippets.

@ronmichael
Created January 30, 2014 20:31
Show Gist options
  • Save ronmichael/8718101 to your computer and use it in GitHub Desktop.
Save ronmichael/8718101 to your computer and use it in GitHub Desktop.
MSSQL: Report on all database objects that have nothing else depending on them - that are not referenced by any other objects in the database.
select o.type_desc type, o.name
from sys.OBJECTS o
left join sys.sql_expression_dependencies ref on ref.referenced_id = o.object_id
left join sys.OBJECTS o2 on o2.object_id = ref.referencing_id
where o2.name is null
and o.type_desc not in ('SYSTEM_TABLE','SQL_TRIGGER','INTERNAL_TABLE','SERVICE_QUEUE','TYPE_TABLE')
and o.type_desc not like '%CONSTRAINT%'
order by o.type_desc, o.name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment