Similar but NOT IDENTICAL to SQL Server 2000 - Query a Table’s Foreign Key relationships
I need a T-SQL statement that will work SQL 2000 that given a table name, will return the foreign key relationships for that table e.g.
Table MyFristTable has a foreign key to MySecondTable, where MyFirstTable.ColA must be in MySecondTable.ColB. I'd be delighted, if the sql statement (or stored proc) is ran for MyFirstTable and returned a result set on the lines of
Column | FK_Table | FK_COLUMN
----------------------------------
ColA | MySecondTable | ColB
NB: I have samples for SQL 2005 that won't work because they rely on sys.foreign_key_columns
I'd rather not have to parse out the results of the sp_help statement.
Thanks,
I had to do this exact thing for a query, and I found this stored procedure, after trying a version much like the sys table one:
exec sp_fkeys @fktable_name = 'foo'
It looks like this is available in SQL Server 2000. Also, I found that in a few cases there were minor differences between this stored proc and the queries here. I'm guessing sp_fkeys is the canonical version.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With