Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Retrieving foreign keys
Message
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Import/Export
Divers
Thread ID:
00851171
Message ID:
00852041
Vues:
9
Well i guest there is not other (and shorter) way to do this :(

thk Mike

Alain

>You can use the Server Enterprise Manager to get most of what you want. Right-click on your database and chose All Tasks | Generate SQL Scripts. In the Generate SQL Scripts dialog, select the tables of interest. On the formating page clear all the checkboxes. On the Options page, select the option Script PRIMARY keys, FOREIGN keys, defaults, and check constraints
>
>Then just weed out the portions of the resulting script that you don't want.
>
>-Mike
>
>>Hi,
>>
>> I want to script all the foreign keys in my data so that i can exporte them to a more recent version of Db but which as lost its foreign keys. I want to do this with having to rebuild all the DB. I was able to find a few information :
>>- foreign key name (fkname)
>>- source table (stname)
>>- source field (sfname)
>>
>>by executing this query :
>>Select TableName.Name as stname, ConsName.Name as fkname, col.sfname
>> from sysobjects ConsName
>> inner join sysobjects TableName
>> on ConsName.Parent_obj = TableName.id
>> inner join sysconstraints cons
>> on cons.constid = ConsName.ID
>> inner join syscolumns col
>> on col.colid = cons.colid and col.id = TableName.id
>> where ConsName.xtype ='F'
>> order by stname, fkname
>>
>>but i'm missing the destination table and field. with these missing pieces I'll be able to reconstruct the script :
>>
>>ALTER TABLE dbo.stname WITH NOCHECK ADD CONSTRAINT fkname FOREIGN KEY
>> (sfname) REFERENCES dbo.dtname (ffid) NOT FOR REPLICATION
>>GO
>>ALTER TABLE dbo.stname NOCHECK CONSTRAINT fkname
>>GO
>>
>>So the question is where does SQL keep the rest of the information on the foreign keys?
>>
>>Alain
>>Analystik
Analystik Team
1430 Belanger
Montreal (Quebec)
Canada
(514) 278-2727
analyste@analystik.ca
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform