﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / Article Discussions / Article Discussions by Author / Discuss content posted by Boka  / Script foreign keys / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Wed, 22 May 2013 07:51:33 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Script foreign keys</title><link>http://www.sqlservercentral.com/Forums/Topic418287-990-1.aspx</link><description>Yes. I figured it out eventually.Thanks &amp; CheersPII</description><pubDate>Fri, 29 Oct 2010 04:44:09 GMT</pubDate><dc:creator>Peter Pirker</dc:creator></item><item><title>RE: Script foreign keys</title><link>http://www.sqlservercentral.com/Forums/Topic418287-990-1.aspx</link><description>Thanks for the script.If you want to disable all the constraints of the database then you can simply use: [code="sql"]EXEC sp_MSforeachtable @command1 = 'alter table ? nocheck constraint all'[/code]</description><pubDate>Fri, 29 Oct 2010 03:47:08 GMT</pubDate><dc:creator>Hardy21</dc:creator></item><item><title>RE: Script foreign keys</title><link>http://www.sqlservercentral.com/Forums/Topic418287-990-1.aspx</link><description>Hi Peter,If you want this script working with different database then you need to use fully qualified name in the form database.schema.object_name in queries and also to add database id in call of OBJECT_SCHEMA_NAME and OBJECT_NAME functions as second argument (see BOL for full syntax). This caused nulls in your result set (the most probably).Regards</description><pubDate>Fri, 29 Oct 2010 02:50:20 GMT</pubDate><dc:creator>Nebojsa Ilic</dc:creator></item><item><title>RE: Script foreign keys</title><link>http://www.sqlservercentral.com/Forums/Topic418287-990-1.aspx</link><description>Works great, but... I need to use it in a stored proc where it should look up the foreign keys from a twin DB, let's call it DB1 and create them in say, DB2.Since switching database context in stored procs is not possible, I prefixed sys.foreign_keys with Db1, and likewise for the column select.Tested the select statements, they produced what looked like correct results, but when I ran the entire statement, all I got was nulls.Switched context to DB1, and it worked again. I've been spinning my wheels on this all afternoon, but can't figure out what goes wrong.</description><pubDate>Wed, 27 Oct 2010 09:37:19 GMT</pubDate><dc:creator>Peter Pirker</dc:creator></item><item><title>RE: Script foreign keys</title><link>http://www.sqlservercentral.com/Forums/Topic418287-990-1.aspx</link><description>I've just tested it and script works (as expected) in SQL 2008 but not in 2000 as Sunshine tried. Sorry</description><pubDate>Fri, 13 Aug 2010 07:35:18 GMT</pubDate><dc:creator>Nebojsa Ilic</dc:creator></item><item><title>RE: Script foreign keys</title><link>http://www.sqlservercentral.com/Forums/Topic418287-990-1.aspx</link><description>Hi §unshine,It works only in SQL Server 2005.Regards.</description><pubDate>Fri, 13 Aug 2010 07:00:15 GMT</pubDate><dc:creator>SQL_ABD</dc:creator></item><item><title>RE: Script foreign keys</title><link>http://www.sqlservercentral.com/Forums/Topic418287-990-1.aspx</link><description>This is the error I get when running thisServer: Msg 170, Level 15, State 1, Line 13Line 13: Incorrect syntax near 'max'.Server: Msg 195, Level 15, State 1, Line 32'OBJECT_SCHEMA_NAME' is not a recognized function name.Server: Msg 137, Level 15, State 1, Line 46Must declare the variable '@object_id'.Server: Msg 137, Level 15, State 1, Line 53Must declare the variable '@AddLine'.Server: Msg 137, Level 15, State 1, Line 55Must declare the variable '@DropLine'.Server: Msg 137, Level 15, State 1, Line 56Must declare the variable '@AddLine'.Server: Msg 137, Level 15, State 1, Line 58Must declare the variable '@AddLine'.Server: Msg 137, Level 15, State 1, Line 60Must declare the variable '@AddLine'.Server: Msg 137, Level 15, State 1, Line 61Must declare the variable '@DropLine'.Server: Msg 137, Level 15, State 1, Line 70Must declare the variable '@parent_object_id'.Server: Msg 137, Level 15, State 1, Line 75Must declare the variable '@fkline'.Server: Msg 137, Level 15, State 1, Line 77Must declare the variable '@pkline'.Server: Msg 137, Level 15, State 1, Line 83Must declare the variable '@fkline'.Server: Msg 137, Level 15, State 1, Line 84Must declare the variable '@pkline'.Server: Msg 137, Level 15, State 1, Line 89Must declare the variable '@fkline'.Server: Msg 137, Level 15, State 1, Line 90Must declare the variable '@pkline'.Server: Msg 137, Level 15, State 1, Line 97Must declare the variable '@AddLine'.Server: Msg 137, Level 15, State 1, Line 99Must declare the variable '@AddLine'.Server: Msg 137, Level 15, State 1, Line 100Must declare the variable '@AddLine'.Server: Msg 137, Level 15, State 1, Line 102Must declare the variable '@AddLine'.Server: Msg 137, Level 15, State 1, Line 122Must declare the variable '@DropScript'.Server: Msg 137, Level 15, State 1, Line 123Must declare the variable '@DropLine'.Server: Msg 137, Level 15, State 1, Line 123Must declare the variable '@AddScript'.Server: Msg 137, Level 15, State 1, Line 125Must declare the variable '@AddLine'.Server: Msg 137, Level 15, State 1, Line 125Must declare the variable '@object_id'.Server: Msg 137, Level 15, State 1, Line 135Must declare the variable '@DropScript'.Server: Msg 137, Level 15, State 1, Line 135Must declare the variable '@AddScript'.</description><pubDate>Mon, 09 Jun 2008 09:00:29 GMT</pubDate><dc:creator>sunshine-587009</dc:creator></item><item><title>RE: Script foreign keys</title><link>http://www.sqlservercentral.com/Forums/Topic418287-990-1.aspx</link><description>See also my script (dec 27 2006, Henk Schreij):Script for all Foreign Keys of all tables of a DB</description><pubDate>Tue, 08 Jan 2008 02:17:22 GMT</pubDate><dc:creator>Henk Schreij</dc:creator></item><item><title>Script foreign keys</title><link>http://www.sqlservercentral.com/Forums/Topic418287-990-1.aspx</link><description>Comments posted to this topic are about the item [B]&lt;A HREF="/scripts/T-SQL/61463/"&gt;Script foreign keys&lt;/A&gt;[/B]</description><pubDate>Sun, 04 Nov 2007 00:41:53 GMT</pubDate><dc:creator>Nebojsa Ilic</dc:creator></item></channel></rss>