Talk:Foreign key

From Wikipedia, the free encyclopedia
Jump to: navigation, search
WikiProject Computing / Software (Rated Start-class, Low-importance)
WikiProject icon This article is within the scope of WikiProject Computing, a collaborative effort to improve the coverage of computers, computing, and information technology on Wikipedia. If you would like to participate, please visit the project page, where you can join the discussion and see a list of open tasks.
Start-Class article Start  This article has been rated as Start-Class on the project's quality scale.
 Low  This article has been rated as Low-importance on the project's importance scale.
Taskforce icon
This article is supported by WikiProject Software (marked as Mid-importance).
 
WikiProject Databases / Computer science  (Rated Start-class, Mid-importance)
WikiProject icon This article is within the scope of WikiProject Databases, a collaborative effort to improve the coverage of database related articles on Wikipedia. If you would like to participate, please visit the project page, where you can join the discussion and see a list of open tasks.
Start-Class article Start  This article has been rated as Start-Class on the project's quality scale.
 Mid  This article has been rated as Mid-importance on the project's importance scale.
Taskforce icon
This article is supported by WikiProject Computer science (marked as Mid-importance).
 

procedural versus declarative[edit]

is it worth mentioning the tension between declarative and procedural notations here? FK constraints as declarataive and equivalent triggers as procedural is a perfect example —Preceding unsigned comment added by 75.87.134.32 (talk) 18:53, 22 April 2009 (UTC)

Remark[edit]

what is key and y we are using primary key and foriegn key in normalization of database.

how do you actually perform a Forgein Key!? i know how primary key looks like, what does a Foreign Key look like? >x<ino 10:58, 2 December 2005 (UTC)

Oy! It took me forever to get to anything that actually explained it. So I added a sentence in the middle to explain it. MikeyTheK 22:22, 10 February 2007 (UTC)

I rewrote most of the article because (so far) the article only gave some examples instead of explaining the concepts of FKs. --Stolze 12:48, 14 February 2007 (UTC)

i want definitions sort and clear,not lengthy as to suit students —Preceding unsigned comment added by 117.97.4.228 (talk) 02:47, 11 September 2007 (UTC)

FK[edit]

The repeated use of the unnecessary abbreviation FK was non-encyclopaedic. Removed.—Preceding unsigned comment added by 86.138.228.61 (talkcontribs)

As far as i can tell , in the section titled "Defining Foreign Keys", the syntax offered for column level referencial constraint in CREATE TABLE:

col3 INTEGER FOREIGN KEY REFERENCES other_table(column_name)

is not correct, according to sql:2003. Instead, it should be:

col3 INTEGER REFERENCES other_table(column_name)

In other words, the FOREIGN KEY keywords should not be there. In fact, the postgresql version shown in the next example is correct according to syntax. Gnarinn (talk) 17:03, 27 March 2008 (UTC)

Vendor support[edit]

Worth mentioning that some major DBMS vendors (MySQL[1]) recognize the statement syntax but don't actually support foreign keys, which means that this functionality will fail silently. Very bad. Ham Pastrami (talk) 06:12, 22 April 2008 (UTC) Clarify: In MySQL you can get foreign keys with the InnoDB engine, but not with other table types. Ham Pastrami (talk) 06:23, 22 April 2008 (UTC)

What does ON UPDATE CASCADE do?[edit]

ON UPDATE CASCADE is in the example. Which means, when the referenced field is modified, the referencing field gets modified too, to the same value.

Turning Foreign Keys Into Triggers[edit]

Foreign key constraints are a shorthand for specifying certain triggers, which are semantically equivalent to the constraints. Here is the genfkey utility from SQLite, as a web service. 75.87.134.77 (talk) 02:42, 20 April 2009 (UTC)

Technical level[edit]

There currently is a link in this article: For a simpler visualization, see VisualCase.com[2] This visualization might serve as a much better example for this article other than DML abstractly describing foreign keys. Group29 (talk) 21:55, 9 June 2009 (UTC) Added Wikipedia:Make technical articles accessible template to this discussion. Group29 (talk) 21:58, 9 June 2009 (UTC)

First few sentences stink...[edit]

This took about four re-reads:

The foreign key identifies a column or a set of columns in one (referencing) table that refers to a set of columns in another (referenced) table. The columns in the referencing table must be the primary key or other candidate key in the referenced table. The values in one row of the referencing columns must occur in a single row in the referenced table. Thus, a row in the referencing table cannot contain values that don't exist in the referenced table (except potentially NULL).

I suggest re-writing to simplify and remove the need for parenthesis. —Preceding unsigned comment added by 76.111.60.215 (talk) 03:12, 23 May 2011 (UTC)

I re-wrote the introduction trying to fix this problem, also some slight mis-statements. Ngriffeth (talk) 03:34, 26 May 2013 (UTC)

Fundamental Misunderstanding[edit]

Much of the article, and especially the very first sentence, is wrong - it conflates the concept of a foreign key with the use of PK-FK constraints to enforce RI. This is a pretty common misunderstanding, but it really shouldn't be perpetuated here! Grumpypierre (talk) 22:39, 30 May 2011 (UTC)

That was my own feeling too, but I have been away from intense involvement in databases for a few years and when I looked in a number of different standard textbooks for discussions of foreign keys, it appears that the idea of foreign key and the idea of referential integrity are inter-twined. I tried to reflect this accurately in my re-write. Ngriffeth (talk) 03:37, 26 May 2013 (UTC)

foreign key example[edit]

there should be some foreign keys examples--Mdtr (talk) 02:32, 31 August 2011 (UTC)

Poorly explained[edit]

This is definitely one of the most vague, ambiguous, and poorly described things I have seen in wikipedia. It tries to cram too much explanation into incomprehensible sentences. In particular, the example for the "order" and "customer" tables needs an explanation from both directions. Also, delete cascades are almost completely unexplained. What happens if there are multiple orders that reference a customer? Does it only delete the customer after the last order referencing the customer is deleted? Does deleting the customer delete all the orders that reference it? Is there a way to make it one-way? Is there a way to have a customer that has no orders? Is there a way to enforce that any customer that exists must have an order? Which table would those constraints go in? Thanks. — Preceding unsigned comment added by 99.253.53.196 (talk) 01:54, 12 September 2013 (UTC)

Candidate key or Superkey?[edit]

The article talks about the foreign key referencing a Candidate key in the referenced table. I dont think that this is entirely accurate. The foreign key must reference a Superkey, but there is no requirement for that Superkey to also be a Candidate key. Candidate key is a smallest possible superkey, and I'm pretty sure a foreign key can reference a superkey which is not in its minimal-most form (ie. is not a candidate key). Jesselong (talk) 13:36, 18 December 2013 (UTC)