Generate Only ForeignKeys Script | SQL Server Performance Forums

SQL Server Performance Forum – Threads Archive

Generate Only ForeignKeys Script

Hi Experts, Is there any way to generate only foreignkey script(CREATE /Drop ) in the database. ie. without Table script. thanks Madhu
It should be doable using the INFORMATION_SCHEMA.REFERENTIAL_CONTRAINTS view. —
Frank Kalis
Moderator
Microsoft SQL Server MVP
Webmaster:http://www.insidesql.de
small error
it is INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS —————————————-
Contributing Editor, Writer & Forums Moderator
http://www.SQL-Server-Performance.Com Visit my Blog at
http://dineshasanka.spaces.live.com/

Oops, thanks! —
Frank Kalis
Moderator
Microsoft SQL Server MVP
Webmaster:http://www.insidesql.de
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnsqlpro03/html/sp03l12.asp —————————————-
Contributing Editor, Writer & Forums Moderator
http://www.SQL-Server-Performance.Com Visit my Blog at
http://dineshasanka.spaces.live.com/

here’s a free tool I wrote that will do this for you: http://www.elsasoft.org/tools.htm EDIT: it generates scripts for ALL objects (including fks), a separate file for each. you could easily modify it to generate scripts for ONLY fks if that’s your need. source code is available. www.elsasoft.org

What about…
select * from sys.foreign_keys
http://msdn2.microsoft.com/en-us/library/ms189807.aspx
Mohammed U.
<blockquote id="quote"><font size="1" face="Verdana, Arial, Helvetica" id="quote">quote:<hr height="1" noshade id="quote"><i>Originally posted by MohammedU</i><br /><br />What about…<br />select * from sys.foreign_keys<br /<a target="_blank" href=http://msdn2.microsoft.com/en-us/library/ms189807.aspx>http://msdn2.microsoft.com/en-us/library/ms189807.aspx</a><br /><br /><br />Mohammed U.<br /><hr height="1" noshade id="quote"></font id="quote"></blockquote id="quote"><br /><br /><br />Pretty cool. [<img src=’/community/emoticons/emotion-1.gif’ alt=’:)‘ />]<br /><br />Thanks,<br />DilliGrg
Hi Mohammed, My qeustion was how to create *Only* ForeignKey script of a Database select * from sys.foreign_keys , this query only will give u the list of FKs I was wondering whether there is any customized script or tool available. I think I must try http://www.elsasoft.org/tools.htm, as told by jezemine
Thanks ….. regards Madhu
If you want details then use sys.foreign_keys view but if you want to create the script to generated for fks then you have to use some tool or sp_OA…. objects…
Mohammed U.
]]>