Skip to content

Instantly share code, notes, and snippets.

@DylanKnevitt
Created September 21, 2015 09:21
Show Gist options
  • Save DylanKnevitt/c88b532f32b810a4a708 to your computer and use it in GitHub Desktop.
Save DylanKnevitt/c88b532f32b810a4a708 to your computer and use it in GitHub Desktop.
Find all tables that do not have any Primary Keys
SELECT * FROM sys.tables st
LEFT JOIN sys.key_constraints kc on kc.parent_object_id = st.object_id and kc.type = 'PK'
WHERE kc.name is null
order by st.name asc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment