x

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?
more ▼

asked Jan 27 '12 at 09:02 AM in Default

Rod gravatar image

Rod
801 46 50 52

(comments are locked)
10|1200 characters needed characters left

2 answers: sort voted first

I think this is what you are looking for.

http://sqlserverpedia.com/wiki/Find_Tables_Without_Primary_Keys

more ▼

answered Jan 27 '12 at 09:05 AM

Chris shaw gravatar image

Chris shaw
530 2 3 5

(comments are locked)
10|1200 characters needed characters left

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.
more ▼

answered Jan 27 '12 at 09:07 AM

JohnM gravatar image

JohnM
6k 1 3 7

(comments are locked)
10|1200 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

New code box

There's a new way to format code on the site - the red speech bubble logo will automatically format T-SQL for you. The original code box is still there for XML, etc. More details here.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

SQL Server Central

Need long-form SQL discussion? SQLserverCentral.com is the place.

Topics:

x1933
x51

asked: Jan 27 '12 at 09:02 AM

Seen: 879 times

Last Updated: Jan 27 '12 at 09:02 AM