﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / Discuss Content Posted by Ravi Lobo / Article Discussions / Article Discussions by Author  / 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 13:41:31 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Foreign Keys</title><link>http://www.sqlservercentral.com/Forums/Topic282433-303-1.aspx</link><description>Hi, Can you help me out in updating such Foreign Key relationships. In one of my tables, i have a FK relationship refering to my primary key of the same table.The Table called MacMaster has following columns:MacID MacName ClusterIDthe ClusterID here is a foreign key referencing the MacID(PK) of the same table.MacID(identity column;PK) MacName ClusterID1                                  Mac1          22                                  Mac2          NULLI was trying to load this table from an another table having following columnMacName ClusterNameMac3          Mac4Mac4          NULLMac5          NULLKindly suggest me a method to load the above data to MacMaster Table.Finally my MacMaster table should have something like this:MacID MacName ClusterID1 Mac1 22 Mac2 NULL3 Mac3 44 Mac4 NULL5 Mac5 NULLIs this can be achieved through TSql or do i need to create a some kind of front end for it.Kindly SuggestRegards,</description><pubDate>Thu, 20 Aug 2009 18:25:59 GMT</pubDate><dc:creator>naveenreddy.84</dc:creator></item><item><title>RE: Foreign Keys</title><link>http://www.sqlservercentral.com/Forums/Topic282433-303-1.aspx</link><description>Hi,   This is really a good article. I had an doubt about that i want to generate the insert statement script for moving the data from one db to another. Nearly 500 tables are there, i want to know how to prioritize the tables list. Becuase each and every tables are internally referenced. Can you please help out to fix the issue</description><pubDate>Thu, 01 Nov 2007 03:02:45 GMT</pubDate><dc:creator>balaji_rcs</dc:creator></item><item><title>RE: Foreign Keys</title><link>http://www.sqlservercentral.com/Forums/Topic282433-303-1.aspx</link><description>&lt;P&gt;No mention of trusted FK's? See &lt;A href="http://sqlblog.com/blogs/hugo_kornelis/archive/2007/03/29/can-you-trust-your-constraints.aspx"&gt;http://sqlblog.com/blogs/hugo_kornelis/archive/2007/03/29/can-you-trust-your-constraints.aspx&lt;/A&gt; Handy to know, especially if you are lumbered with a db that exposes all data through very complex (and poorly performing &lt;img src='images/emotions/angry.gif' height='20' width='20' border='0' title='Angry' align='absmiddle'&gt; )views!&lt;/P&gt;</description><pubDate>Mon, 11 Jun 2007 22:24:00 GMT</pubDate><dc:creator>nogoodboyo</dc:creator></item><item><title>RE: Foreign Keys</title><link>http://www.sqlservercentral.com/Forums/Topic282433-303-1.aspx</link><description>To not use FKs in an OLTP with any level of complexity is just plain ignorant. There is no excuse for it, and you will just get badly burned. Amazingly enough, through my career I've had to fight developers, managers, and even other DBAs in order to install FKs on databases! It's incredible. In almost every case, they have grown to see the rewards by catching logic / data problems in testing with the FKs. Not to mention happy customers...</description><pubDate>Thu, 31 May 2007 05:48:00 GMT</pubDate><dc:creator>Vic Kirkpatrick-173212</dc:creator></item><item><title>RE: Foreign Keys</title><link>http://www.sqlservercentral.com/Forums/Topic282433-303-1.aspx</link><description>&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;Thank you all for your suggestions! &lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/P&gt;</description><pubDate>Thu, 20 Jul 2006 06:25:00 GMT</pubDate><dc:creator>Ravi Prashanth Lobo-275382</dc:creator></item><item><title>RE: Foreign Keys</title><link>http://www.sqlservercentral.com/Forums/Topic282433-303-1.aspx</link><description>&lt;P&gt;As usual I am a day late and a dollar short, but heck was a good, clear, concise tutorial on foreign keys.&lt;/P&gt;&lt;P&gt;Thanks for the effort you put into this ... and as suggested by some one else, would be nice if you took the challenge and attempted to 'explain' the many to many relationship.&lt;/P&gt;&lt;P&gt;Again - thanks&lt;/P&gt;&lt;P&gt; &lt;/P&gt;</description><pubDate>Wed, 14 Jun 2006 07:16:00 GMT</pubDate><dc:creator>bitbucket-25253</dc:creator></item><item><title>RE: Foreign Keys</title><link>http://www.sqlservercentral.com/Forums/Topic282433-303-1.aspx</link><description>&lt;P&gt;Fair comment from Roger.  Makes me think actually that the next step for the article would be many-many relationship as many &lt;img src='images/emotions/biggrin.gif' height='20' width='20' border='0' title='Big Grin' align='absmiddle'&gt; people get that confused&lt;/P&gt;</description><pubDate>Sat, 03 Jun 2006 00:40:00 GMT</pubDate><dc:creator>Ian Yates</dc:creator></item><item><title>RE: Foreign Keys</title><link>http://www.sqlservercentral.com/Forums/Topic282433-303-1.aspx</link><description>Good, terse explanation.The only issue I'd have with it is the use of the terminology "Parent" and "Child" to describe the relationship between the primary key and the foreign key(s) that reference it.  In the best methodologies I've seen, the terms "parent" and "child" are reserved for unusual situations where you have things that depend for their existence on other things.  An example of this might be a line on an invoice - the invoice must exist for the line to exist, do the invoice would be the "parent" and the line the "child".  With dissimilar things, such as drivers and racecars, you'd have two distinct entities that were related by a foreign key, but neither would be the "parent" of the other.That's terminology, but it avoids confusion.</description><pubDate>Fri, 02 Jun 2006 13:04:00 GMT</pubDate><dc:creator>Roger Thomas</dc:creator></item><item><title>RE: Foreign Keys</title><link>http://www.sqlservercentral.com/Forums/Topic282433-303-1.aspx</link><description>&lt;PRE&gt;&lt;img src='images/emotions/blink.gif' height='20' width='20' border='0' title='Blink' align='absmiddle'&gt; &lt;FONT color=#dd33dd&gt;&lt;STRONG&gt;If you don’t have a key, you don’t have a table&lt;/STRONG&gt;&lt;/FONT&gt;! &lt;img src='images/emotions/wow.gif' height='20' width='20' border='0' title='Wow' align='absmiddle'&gt;    &lt;FONT color=#7777dd&gt;&lt;STRONG&gt;                  - Joe Celko&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/PRE&gt;&lt;PRE&gt;It is very nice article                 which one can easly understand                 without &lt;FONT color=#dd33dd&gt;&lt;STRONG&gt;deep&lt;/STRONG&gt;&lt;/FONT&gt; knowlege of &lt;FONT color=#ff11ff&gt;&lt;STRONG&gt;MSSQL&lt;/STRONG&gt;&lt;/FONT&gt;.&lt;/PRE&gt;&lt;PRE&gt;Also basic concepts are explained very well !!!!!&lt;/PRE&gt;&lt;PRE&gt; &lt;/PRE&gt;&lt;PRE&gt; &lt;/PRE&gt;</description><pubDate>Thu, 01 Jun 2006 11:39:00 GMT</pubDate><dc:creator>Deepak Patil-309214</dc:creator></item><item><title>RE: Foreign Keys</title><link>http://www.sqlservercentral.com/Forums/Topic282433-303-1.aspx</link><description>&lt;P&gt;I think General Patton said:  "Fixed fortifications are a monument man's stupidity."  Same could be said for "generic" database applications.&lt;/P&gt;</description><pubDate>Thu, 01 Jun 2006 08:06:00 GMT</pubDate><dc:creator>Mike C</dc:creator></item><item><title>RE: Foreign Keys</title><link>http://www.sqlservercentral.com/Forums/Topic282433-303-1.aspx</link><description>&lt;P&gt;Good article - I too have come across some rather powerful systems with no FKs.  Their excuse was that when data loading they could do it in any order.  I might send them your quick and easy code to disable and enable all constraints.&lt;/P&gt;&lt;P&gt;Hope this article influences some folk to ensure they use ref integrity! &lt;img src='images/emotions/smile.gif' height='20' width='20' border='0' title='Smile' align='absmiddle'&gt;&lt;/P&gt;</description><pubDate>Thu, 01 Jun 2006 03:45:00 GMT</pubDate><dc:creator>Ian Yates</dc:creator></item><item><title>RE: Foreign Keys</title><link>http://www.sqlservercentral.com/Forums/Topic282433-303-1.aspx</link><description>&lt;P&gt;&lt;SPAN id=Showtread1_ThreadRepeater__ctl7_lblFullMessage&gt;"Recently I came across a highly transactional DB with no FK's! The data integrity was managed by the front-end application."&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I've seen this also.  The ERP system was designed to be "generic" - any database platform, on any OS, for any customer.  As customers all have differing requriements, an FK for one might be detrimental to another, so all were left off.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;And then, as the "customer", we paid a fortune getting the application customised to check the data integrity we required.  A nice little earner, I must say.  &lt;img src='images/emotions/wink.gif' height='20' width='20' border='0' title='Wink' align='absmiddle'&gt;&lt;/SPAN&gt;&lt;/P&gt;</description><pubDate>Wed, 31 May 2006 17:19:00 GMT</pubDate><dc:creator>Fal</dc:creator></item><item><title>RE: Foreign Keys</title><link>http://www.sqlservercentral.com/Forums/Topic282433-303-1.aspx</link><description>"Recently I came across a highly transactional DB with no FK's! The data integrity was managed by the front-end application."Another reason for this happening is that vendors try to hide proprietary information architecture.  No referential integrity, combined with generic object names and procedures/function definitions created on one line.  (Great Pains first comes to my mind.)  With setup like that, it is really painful to "untagle" relationships at the backend.</description><pubDate>Wed, 31 May 2006 15:42:00 GMT</pubDate><dc:creator>SL10</dc:creator></item><item><title>RE: Foreign Keys</title><link>http://www.sqlservercentral.com/Forums/Topic282433-303-1.aspx</link><description>&lt;P&gt;I really liked the script that will traverse the FK hierarchy.  However, it looks like it will only work as long as there is no recursiveness - if a table has a FK within it to itself, the code will loop forever trying to traverse the same table over and over again.&lt;/P&gt;</description><pubDate>Wed, 31 May 2006 12:48:00 GMT</pubDate><dc:creator>Jason-262847</dc:creator></item><item><title>RE: Foreign Keys</title><link>http://www.sqlservercentral.com/Forums/Topic282433-303-1.aspx</link><description>&lt;tt&gt;Recently I came across a highly transactional DB with no FK's! The data integrity was managed by the front-end application.&lt;/tt&gt;Unfortunately this is not uncommon in database / application design.  I can't tell you the number of vendor-supplied applications I've looked at that don't make use of basic database features such as keys, indexes or constraints.  Not to offend anyone, but it usually happens when you've got front-end developers driving the whole thing without a good DBA adding input.  When I came to my current position, the developers were running the show and I had to slowly bring them over to agreeing to use things like stored procedures, constraints, keys and db-side functions.Also, while there are many things I have fundimental disagreements with Celko on, I do like that quote as well.Good article.</description><pubDate>Wed, 31 May 2006 12:30:00 GMT</pubDate><dc:creator>Aaron Ingold</dc:creator></item><item><title>RE: Foreign Keys</title><link>http://www.sqlservercentral.com/Forums/Topic282433-303-1.aspx</link><description>&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;&lt;FONT face="Times New Roman"&gt;You got me there!&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;&lt;FONT face="Times New Roman"&gt;Yes, Celko is referring to primary keys. &lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman"&gt; &lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;&lt;FONT face="Times New Roman"&gt;That was my favorite quote. I wanted to have it in my first article.&lt;SPAN style="mso-spacerun: yes"&gt;  &lt;/SPAN&gt;Hope it will not harm someone….&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;</description><pubDate>Wed, 31 May 2006 06:19:00 GMT</pubDate><dc:creator>Ravi Prashanth Lobo-275382</dc:creator></item><item><title>RE: Foreign Keys</title><link>http://www.sqlservercentral.com/Forums/Topic282433-303-1.aspx</link><description>&lt;SPAN id=Postmessage1_ucMessageControl_ReplyMsgRepeater__ctl1_lblFullMessage&gt; &lt;FONT size=2&gt;Interesting article. &lt;IMG title=Smile height=20 src="http://www.sqlservercentral.com/forums/images/emotions/smile.gif" width=20 align=absMiddle border=0&gt; Most of things are well known, but here they are summarized and there are also some interesting ideas.&lt;/FONT&gt;&lt;P&gt;The most curious for me was this one:&lt;/P&gt;&lt;P&gt;&lt;HR&gt;&lt;P&gt;&lt;/P&gt;&lt;H3&gt;Recursive &lt;/H3&gt;&lt;P&gt;I can not imagine any practical use of below code, but theoretically it is possible. &lt;PRE&gt;&lt;FONT color=#3300ff size=2&gt;CREATE TABLE master( pkey int PRIMARY KEY FOREIGN KEY (pkey) REFERENCES master(pkey))&lt;/FONT&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;HR&gt;&lt;/PRE&gt;&lt;PRE&gt;It really does nothing. I hoped it will prevent update of PK and deleting a record, so I tried it, but unfortunately it doesn't prevent either PK update nor record deleting.&lt;/PRE&gt;&lt;/SPAN&gt;</description><pubDate>Wed, 31 May 2006 04:07:00 GMT</pubDate><dc:creator>geovar</dc:creator></item><item><title>RE: Foreign Keys</title><link>http://www.sqlservercentral.com/Forums/Topic282433-303-1.aspx</link><description>&lt;P&gt;You got my vote &lt;img src='images/emotions/smile.gif' height='20' width='20' border='0' title='Smile' align='absmiddle'&gt;  In that Celko quote, I think he was specifically referring to a Primary Key.&lt;/P&gt;</description><pubDate>Tue, 30 May 2006 21:45:00 GMT</pubDate><dc:creator>Mike C</dc:creator></item><item><title>Foreign Keys</title><link>http://www.sqlservercentral.com/Forums/Topic282433-303-1.aspx</link><description>Comments posted to this topic are about the content posted at &lt;A HREF="http://www.sqlservercentral.com/columnists/rlobo/foreignkeys.asp"&gt;http://www.sqlservercentral.com/columnists/rlobo/foreignkeys.asp&lt;/A&gt;</description><pubDate>Wed, 24 May 2006 08:05:00 GMT</pubDate><dc:creator>Ravi Prashanth Lobo-275382</dc:creator></item></channel></rss>