Skip to content

Instantly share code, notes, and snippets.

@joe-oli
Created January 21, 2019 08:52
Show Gist options
  • Save joe-oli/3a7239bf2583610279f61f016fc61852 to your computer and use it in GitHub Desktop.
Save joe-oli/3a7239bf2583610279f61f016fc61852 to your computer and use it in GitHub Desktop.
sql server random notes
-- Find tables without primary keys (PKs) in SQL Server database
select schema_name(tab.schema_id) as [schema_name],
tab.[name] as table_name
from sys.tables tab
left outer join sys.indexes pk
on tab.object_id = pk.object_id
and pk.is_primary_key = 1
where pk.object_id is null
order by schema_name(tab.schema_id),
tab.[name]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment