Finding all SQL Database tables with no primary key

A colleague just forwarded me this little script for tracking down SQL Server database tables which don't have a primary key assigned. It's cute and useful, so I thought I'd blog it, as much for my own archiving purposes as for anything else

Use <databasename> -- where <databasename> is the name of your database

Go

select o.name from sysobjects o

join sysindexes i on o.id=i.id

where o.type ='u' -- user table

and i.indid=0 -- no index

order by o.name

Go

enjoy

posted @ Monday, October 30, 2006 1:38 PM

Print

Comments on this entry:

No comments posted yet.

Your comment:



 (will not be displayed)


 
 
 
Please add 2 and 7 and type the answer here:
 

Live Comment Preview:

 
«August»
SunMonTueWedThuFriSat
25262728293031
1234567
891011121314
15161718192021
22232425262728
2930311234
 
 
 
Sydney Atheists on Facebook
Join the best atheist themed blogroll!