|WikiProject Computing / Software||(Rated Start-class, Low-importance)|
|WikiProject Databases / Computer science||(Rated Start-class, Mid-importance)|
||This article may be too technical for most readers to understand. (September 2010) (Learn how and when to remove this template message)|
procedural versus declarative
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 184.108.40.206 (talk) 18:53, 22 April 2009 (UTC)
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)
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)
Worth mentioning that some major DBMS vendors (MySQL) 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?
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
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. 220.127.116.11 (talk) 02:42, 20 April 2009 (UTC)
There currently is a link in this article: For a simpler visualization, see VisualCase.com 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...
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 re-wrote the introduction trying to fix this problem, also some slight mis-statements. Ngriffeth (talk) 03:34, 26 May 2013 (UTC)
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
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 18.104.22.168 (talk) 01:54, 12 September 2013 (UTC)
26 jan 2016 - first line 'simpler explanation' is grammatically incorrect
Candidate key or Superkey?
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)