Well, I worked it out myself - here it is for everyone else ...
select 'create index IX_'+c.name+'_'+p.name+' on '+c.name+'('+cf.name+');' from sysforeignkeys fk join sysobjects c on fk.fkeyid=c.id join sysobjects p on fk.rkeyid=p.id join syscolumns cf on c.id=cf.id and cf.colid = fk.fkey left join sysindexkeys k on k.id = cf.id and k.colid = cf.colid where k.id is null order by c.name
It does not work 100%, for example, if you have two FKs on the same table in the same primary table, but there are few of them (at least in my database), that I could fix them manually with confidence.
Shaul behr
source share