Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
| Search | Today's Posts | Mark Forums Read
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 27th, 2008, 02:38 AM
jomet
Guest
 
Posts: n/a
Default list foreign keys in sql 2000

Hi,

i want to get foreign key details for some validation

foreign key name | owner column | Referred Table | Referred column

of a specified table

how can i do it?
please help me
thanks
:)

jomet.
---------------------------------------------
Once you start a working on something,
dont be afraid of failure and dont abandon it.
People who work sincerely are the happiest.
 
Old May 1st, 2008, 03:54 PM
Registered User
 
Join Date: May 2008
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I believe the following is what you're looking for:

SELECT OBJECT_NAME(constid), target_table.name AS target_table, target_column.name AS target_column,
    source_table.name AS source_table, source_column.name AS source_column
FROM sysforeignkeys fk
INNER JOIN sysobjects target_table ON fk.fkeyid = target_table.id
INNER JOIN syscolumns target_column ON fk.fkeyid = target_column.id AND fk.fkey = target_column.colid
INNER JOIN sysobjects source_table ON fk.rkeyid = source_table.id
INNER JOIN syscolumns source_column ON fk.rkeyid = source_column.id AND fk.rkey = source_column.colid
ORDER BY OBJECT_NAME(constid), target_table.name

Good luck.

Mark
 
Old May 1st, 2008, 11:15 PM
jomet
Guest
 
Posts: n/a
Default

Thanks for your solution.


jomet.
`````````````````````````````````````````````````` ``````````````````````
Once you start a working on something, dont be afraid of failure and dont abandon it.
People who work sincerely are the happiest.




Similar Threads
Thread Thread Starter Forum Replies Last Post
SQL Design: Foreign Key to Multiple Primary Keys? kalel_4444 BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 10 May 8th, 2008 04:14 PM
list foreign keys jomet Oracle 2 March 28th, 2008 04:17 AM
Copying Databases & Foreign Keys donevco Access 5 February 20th, 2007 08:31 AM
inserting records with foreign and primary keys tdaustin Classic ASP Basics 0 October 4th, 2005 12:49 AM
transfering identites as foreign keys santaji SQL Server DTS 1 September 23rd, 2003 09:28 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.