Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Problem with sp_foreignkeys

Author  Topic 

Pablo Javier
Starting Member

1 Post

Posted - 2007-04-19 : 09:30:04
Hi,

I am working with Sql Server 2005.
I have a Linked Server (to an Access database) from which I want to get the foreign keys of its tables.
To do that I use the store procedure sp_foreignkeys.
The problem is that in a table that I have two foreign keys to the same table, which are multicolumn keys, I can’t identify the keys with the result of the stored procedure because it returns first the records with KEY_SEQ=1 and then the records with KEY_SEQ=2, and in this records is impossible to solve to which relations they belong because there is not field identifying the relation.

For example:

TableA
IdCol1
IdCol2

TableB
FK1TableA_IdCol1
FK1TableA_IdCol2
FK2TableA_IdCol1
FK2ItableA_IdCol2

The relations are:
Foreign Key Primary Key
TableB TableA
Relation1:
FK1TableA_IdCol1 -> IdCol1
FK1TableA_IdCol2 -> IdCol2
Relation2:
FK2TableA_IdCol1 -> IdCol1
FK2TableA_IdCol2 -> IdCol2

When i get the records from the stored procedure, it gives the following result:

PKTABLE_NAME PKCOLUMN_NAME FKTABLE_NAME FKCOLUMN_NAME KEY_SEQ
TableA IdCol1 TableB FK1TableA_IdCol1 1
TableA IdCol1 TableB FK2TableA_IdCol1 1
TableA IdCol2 TableB FK1TableA_IdCol2 2
TableA IdCol2 TableB FK2TableA_IdCol2 2


The other fields are returned with NULL value.

When I try to identify the keys, I can’t differentiate to which key the third record belongs, becouse there is no field identifying the relation, so I can’t know if it belongs to Relation1 or to Relation2. The same with the fourth record.

Am I missing something that allow me to identify the relation?
Is it a bug in the store procedure?
Is there any other way to get the relations?

Thanks in advance!

Pablo
   

- Advertisement -