question

Rod avatar image
Rod asked

How to find tables without primary keys

I found, much to my surprise (horror), that we've got some tables without primary keys. As it turns out they're lookup tables, so they're pretty static, but still... Now I'm wondering, do we have other tables without primary keys? Is there some DDL query I can run, to list all tables without primary keys?
sql-server-2005sql-server-express
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Chris shaw avatar image
Chris shaw answered
I think this is what you are looking for. http://sqlserverpedia.com/wiki/Find_Tables_Without_Primary_Keys
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

JohnM avatar image
JohnM answered
Here's an older answer: http://www.mssqltips.com/sqlservertip/1237/finding-primary-keys-and-missing-primary-keys-in-sql-server/ The author shows you a script for 2005, but it worked fine in my 2008 environment. Give it a shot.
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.