Yesterday, I encountered a disturbing ramification of using a new baseline database in our development environment. The new baseline did not have primary keys on four of the tables; which is a requirement of our Codesmith templates. Tom, my scrum master, was good enough to provide me with this script for ascertaining which tables in a database have no primary key.

select name from sysobjects
where type = 'U'
and id not in
(
select o.id from sysobjects i
inner join sysobjects o
on o.id = i.parent_obj
where i.xtype = 'pk'
)

Advertisements