Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to query system tables for FK constraints
Message
De
04/06/2001 14:04:28
 
 
À
Tous
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Titre:
How to query system tables for FK constraints
Divers
Thread ID:
00514723
Message ID:
00514723
Vues:
44
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
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform