Get all child table and key names of a parent table
Posted in 2006
select stab.tabname Parent, scol.colname Primary_key, sstab.tabname Child, sscol.colname Child_key from syscolumns scol, syscolumns sscol, sysindexes sind, sysindexes ssind, sysconstraints scon, sysconstraints sscon, systables stab, systables sstab, sysreferences sref where scol.tabid=sind.tabid and scol.colno = sind.part1 and sind.idxname=scon.idxname and stab.tabid=scon.tabid and sstab.tabid=sscon.tabid and sscol.tabid = ssind.tabid and (sscol.colno = ssind.part1 or sscol.colno = ssind.part2) and sscon.idxname=ssind.idxname and sref.constrid=sscon.constrid and stab.tabid=sref.ptabid and stab.tabname='ParentTableName' above query works gr8 when single column primary key in Parent table, but when there is two or morecolumn primary key it does not gives right ans. plz try to solve..