Posted by Marcin A. Guzowski on 06/23/07 13:00
ArunDhaJ wrote:
> Hi Friends,
> Is there any way to get the table name which is referenced by the
> foreign key
> (..)
(SQL Server 2005)
IMHO the easiest way is to use sys.foreign_keys. You don't need any
other system view. Try this:
USE YOUR_DATABASE; -- remember about current database context
SELECT
OBJECT_NAME(parent_object_id) as table_with_FK,
OBJECT_NAME(referenced_object_id) as referenced_table
FROM sys.foreign_keys
WHERE OBJECT_NAME(parent_object_id) = 'Staff'
--
Best regards,
Marcin Guzowski
http://guzowski.info
[Back to original message]
|