Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to query system tables for FK constraints
Message
From
04/06/2001 14:04:28
 
 
To
All
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Title:
How to query system tables for FK constraints
Miscellaneous
Thread ID:
00514723
Message ID:
00514723
Views:
43
Hello,

SQL Server 6.5.
I need to drop all the constraints, load some data, then re-create the constraints. I was thinking that I should be able to query the system tables to generate the SQL for re-creating the constraints.

Can this be done?

If so, then I have gotten as far as building a list of table_name, contraint_name, referencing_table, referenced_table by joining sysobjects with sysreferences. I cannot figure out what to join to get the referenced columns. Here is what I have so far ...
select so.name as table_name,
	sofkc.name as fk_constraint,
	sr.constid, sofkc.id,
	so2.name as referencing_table_name,
	so3.name as refered_table_name
from 	sysobjects so, sysobjects sofkc, sysreferences sr, 
	sysobjects so2, sysobjects so3
where so.name = 'shopper'
and so.type = 'U'
and sofkc.type = 'F'
and sr.constid = sofkc.id
and sr.fkeyid = so2.id
and sr.rkeyid = so3.id
order by table_name, fk_constraint
I have included a table name in the where clause (so.name = 'shopper') to make it easier to determine if I'm getting what I want. However, once I have it working, I would like to get all the tables.

Any suggestions would be greatly appreciated.

TIA,
-Isaac
Next
Reply
Map
View

Click here to load this message in the networking platform