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.
«October»
SunMonTueWedThuFriSat
293012345
6789101112
13141516171819
20212223242526
272829303112
3456789
 
Vaccination Saves Lives: Stop The Australian Vaccination Network
 
 
Say NO to the National School Chaplaincy Program