with pk as (select * from dbo.DbLayout where IsPkey = 1)
,other as (select * from dbo.DbLayout where IsPkey = 0)
select
pk.ColumnName
,PkTable = pk.TableName
,OnTable = o.TableName
,sql = 'alter table [' + o.TableName + '] with check add constraint [FK_'
+ o.TableName + '_' + pk.TableName + '] foreign key ([' + pk.ColumnName
+ ']) references [' + pk.TableName + '] ([' + pk.ColumnName + '])'
from
pk
inner join other o
on pk.ColumnName = o.ColumnName
order by
1,2