Deprecated: YoastSEO_Vendor\Symfony\Component\DependencyInjection\Container::__construct(): Implicitly marking parameter $parameterBag as nullable is deprecated, the explicit nullable type must be used instead in /home/nubelus/sharedove/adisjugo/wp-content/plugins/wordpress-seo/vendor_prefixed/symfony/dependency-injection/Container.php on line 60
Where are my foreign keys? - Adis Jugo blog
Select Page

Where are my foreign keys?

If you would ever, from whatever reason, need to check/validate/list foreign keys in the MS SQL 2000/2005 database, here is the magical query you won’t find on msdn:

SELECT sysforeignkeys.constid, sysforeignkeys.fkeyid,
sysforeignkeys.rkeyid, sysobjects.name as keyname,
soFK.name AS firsttable, soRK.name as secondtable
FROM sysforeignkeys
LEFT OUTER JOIN sysobjects soKey ON sysforeignkeys.constid = soKey.id
LEFT OUTER JOIN sysobjects soFK ON sysforeignkeys.fkeyid = soFK.id
LEFT OUTER JOIN sysobjects soRK ON sysforeignkeys.rkeyid = soRK.id

Column names (linked columns) are not included in query – I didn’t need it for my purpose, but you can include them of course.

Previous

Next