x
login about faq Site discussion (meta-askssc)

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 37 47 51

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

2 answers: sort voted first
more ▼

answered Jan 27 '12 at 09:05 AM

Chris shaw gravatar image

Chris shaw
520 1 2 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
4.5k 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.

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



Facebook logo Follow Ask SSC on Facebook
Find Ask SSC on Google+
linkedin logo Find us on LinkedIn

Topics:

x1834
x48

asked: Jan 27 '12 at 09:02 AM

Seen: 442 times

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

Copyright © 2002-2012 Simple Talk Publishing. All Rights Reserved. If you have any queries, please contact the site administrators.
Ask SQL Server Central is a community service provided by Red Gate.