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

 
 
 
Comments have been closed on this topic.
«November»
SunMonTueWedThuFriSat
272829303112
3456789
10111213141516
17181920212223
24252627282930
1234567
 
Vaccination Saves Lives: Stop The Australian Vaccination Network
 
 
Say NO to the National School Chaplaincy Program