Raport relatii PK-FK intre tabele

Configurare noua (How To)

Situatie

Pentru usurinta administrarii unui server de sql am facut o procedura ce returneaza legaturile PK – FK dintre toate tabelele de pe baza pe care este rulata.

Solutie

create procedure BD_RelationshipPK_FK_prc

as

select s1.name as ‘SourceTable’,
c1.name as ‘SourceColumn_PK’,
s2.name as ‘TargetTable’,
c2.name as ‘TargetColumn_FK’

from sysReferences sr
join sysobjects s1 on (sr.rkeyid=s1.id)
join sysobjects s2 on (sr.fkeyid=s2.id)
join syscolumns c1 on (s1.id=c1.id and sr.rkey1=c1.colid)
join syscolumns c2 on (s2.id=c2.id and sr.fkey1=c2.colid)

order by 1, 2, 4

Tip solutie

Permanent
Etichetare:

Voteaza

(9 din 15 persoane apreciaza acest articol)

Despre Autor

Leave A Comment?