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.
«December»
SunMonTueWedThuFriSat
24252627282930
1234567
891011121314
15161718192021
22232425262728
2930311234
 
Vaccination Saves Lives: Stop The Australian Vaccination Network
 
 
Say NO to the National School Chaplaincy Program