Foreign Keys - CompWisdom
About us  |  Why use us?  |  Press  |  Contact us

 

Topic: Foreign Keys


  
 De-Embedding Foreign Keys: Part 1
To do this, we must drop a foreign key column, add an associative table, recast the data in the two related tables into this three-table format and change all the SQL and code that references the relationship to find it in the associative table instead of in a column of one of the related tables.
When a foreign key is put into one of the tables that it relates, it is embedded in that table.
This is because an embedded foreign key is a column in one table of the relationship; and as a column of a relational table, it can contain only one value.
http://www.dmreview.com/editorial/newsletter_article.cfm?nl=dmdirect&articleId=2308   (2066 words)

  
 Relational Model: Relationships and Keys
The relationship is made between two relational tables by matching the values of the foreign key in one table with the values of the primary key in another.
Keys are fundamental to the concept of relational databases because they enable tables in the database to be related with each other.
Navigating between tables requires that the foreign key is able to correctly and consistently reference the values of the primary keys of a related table.
http://www.utexas.edu/its/windows/database/datamodeling/rm/rm4.html   (271 words)

  
 Practical database design, Part 1
Foreign keys are table attributes, the values of which are the primary keys of another table.
Furthermore, the surrogate key typically is a single field (not a compound key), which simplifies the schema (particularly when the key is used in other tables as a foreign key).
Such a business data candidate key is a subset of all attributes, the values of which are never null, and each combination of values is unique.
http://www-128.ibm.com/developerworks/web/library/wa-dbdsgn1.html   (3062 words)

  
 Maintaining Data Integrity Through Constraints
When nulls are not allowed in a foreign key, each row in the child table must explicitly reference a value in the parent key because nulls are not allowed in the foreign key.
When referenced data in the parent key is deleted, all rows in the child table that depend on those parent key values have their foreign keys set to null.
To enforce the "match full" rule for nulls in composite foreign keys, which requires that all components of the key be null or all be non-null, define a
http://www.ucs.louisiana.edu/~oracle9i/appdev.901/a88876/adg05itg.htm   (5365 words)

  
 MySQL Database Design
Foreign keys are the representation of the primary key from Table A in Table B. If you have a movies database with a movie table and a director table, the primary key from director would be linked as a foreign key in movie.
Hence, foreign keys in MySQL are more of a theoretical presence than a binding one, although this should change in later versions of the software.
Currently, MySQL formally implements foreign keys only when using the InnoDB table type (see Chapter 11, "Advanced MySQL," for more information on the different table types) but generally ignores their existence otherwise.
http://www.peachpit.com/articles/article.asp?p=30885&seqNum=2   (563 words)

  
 More on Primary and Foreign Keys:
Again, the table containing the foreign key is considered the child and the table containing the primary key is considered the parent.
The majorcode can then be set up as a foreign key on the tables from which you want to link in.
When records are inserted in this table, they must match the integrity of the primary key which calls for no duplicates and no nulls.
http://www.bristol.mass.edu/pgrocer/cis50/presentations/moreprimaryfor.htm   (942 words)

  
 Primary and Foreign Keys
Page 118 of {Date95} says "A foreign key value represents a reference to the tuple containing the matching candidate key value (the referenced tuple or target tuple)." So a primary key may not be necessary for referential integrity.
This insures that the value to which the foreign key refers will always be valid (or null, if allowed).
Our current position, by contrast, resembles our current position on primary keys in general: Requiring foreign keys to match primary keys specifically is probably a good idea in many cases - even in most cases - but it cannot be justified in all cases, unequivocally."
http://www.aisintl.com/case/primary_and_foreign_key.html   (922 words)

  
 DB2 Help
A foreign key is a column or set of columns in a table whose values are required to match at least one primary key value of a row of its parent table.
Some component of the foreign key is null.
After the table is created, you must use the Alter function to add, change, or remove foreign keys.
http://www.seas.ucla.edu/db2/db2help/pgta-21.htm   (119 words)

  
 SQL Server Forums at SQLTeam.com - too many foreign keys?
The only other solution, would not to have foreign keys but I think that will open us up to data integrety issues (lose child records -- extra data which will never be referenced).
Each set of data which affects rating is stored in a rating table, which has a foreign key associated with the main "Companies" table.
You need to look at your design and see how you can make it the most efficient, while maintaining this integrity.
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=37033   (704 words)

  
 Foreign Keys and Permitted RDBMS Operations
In the ENROLL object, the Course_Code is a foreign key because it is a part of the key field and referes to the entire key field for the COURSE object.
Similarly, the Student_Number is a foreign key since it refers to the entire key field for the STUDENT object.
An object (file) that has a part of a key field (one field in a compound field key) that refers to a complete key in another object (file) is said to have a "Foreign Key." For example:
http://www.uwf.edu/wbeatty/ism4113/chap69/permit.html   (605 words)

  
 [No title]
When we add a Foreign key to the table, we are creating a)Tj 0 -13.2 Td(dependency between the table for which we define the Foreign key \(the referencing table\))Tj -0 -13.2 Td(and the table your Foreign key references \(the referenced table\).
Alternate keys are not considered to be the)Tj -0 -10.8 Td(unique identifier of a record in a table.
Once we have set up a)Tj 0 -13.2 Td(Foreign key for a table, any record inserted into the referencing table must either have a)Tj 0 -13.2 Td(matching record in the referenced column\(s\) of the referenced table, or the value of the)Tj 0 -13.2 Td(Foreign key column must be set to NOTNULL.
http://www.aspfree.com/index2.php?option=content&do_pdf=1&id=2088&hide_js=1   (2439 words)

  
 Offline Tables and Foreign Keys
Import all tables that have a foreign key relationship, whether you intend to change them or not, so that you generate the correct information about the foreign keys to a SQL file or directly to the database.
In the case that JDeveloper imports a table that has a foreign key, but the table at the other end of the key is not imported, the foreign key information is present but hidden.
This means that if you work on one or more table definitions offline and then generate the information back to the original database, foreign keys may be lost.
http://www.oracle.com/webapps/online-help/jdeveloper/10.1.3/state/content/vtTopicFile.dboff_tablesandfks~html/navId.v/navSetId._/oldNavSetId._/vtReset.true/oldNavId.0   (501 words)

  
 Foreign Keys - steps to enable - The MySQL Relational Database
Since foreign keys just maintain integrity, they don't provide a means by which you can enter data that goes into several tables at a time (quite the reverse - they can prevent you adding information to a child table when there isn't a matching element in the parent).
Foreign keys have only limited support / us in MySQL; they're only available if you're using InnoDB tables, and they're used just to maintain the integrity of data between your tables.
I understand how I can join the tables using SQL queries, but with the contact details table, the primary key, wont be available for the user to select from a drop down box, so how do I get that value into the main table.
http://www.wellho.net/forum/The-MySQL-Relational-Database/Foreign-Keys-steps-to-enable.html   (1601 words)

  
 JBoss.com - Forums - CMR relation on NOT NULL foreign keys
But it is a problem when the key is generated by the database and some foreign keys cannot be null.
This foreign key is further restricted by a NOT NULL constraint.
Since the CMR relation on the foreign key has to be set in ejbPostCreate() but the database insert takes place between the ejbCreate() and ejbPostCreste() methods, it fails due to a voilated NOT NULL constraint.
http://www.jboss.org/?module=bb&op=viewtopic&t=43591   (1041 words)

  
 Foreign Keys [EA User Guide]
Hint: If you are defining a MySQL database and wish to use foreign keys, you will have to set the table type to allow this.
Click on the table that will contain the foreign key (source) and draw a connector to the other table (target).
Locate the required tables in either a diagram or in the Project Browser.
http://www.sparxsystems.com.au/EAUserGuide/foreignkeys.htm   (356 words)

  
 AskTom "Indexes on foreign keys"
There is no key it can be related to in parent since NULL = NULL is not true and NULL != NULL is not true.
Dear Tom, We understand that indexing foreign keys will solve the table level locking issue especially during update/delete the primary key value from the parent table apart from improving the query performance in certain conditions.
In addition to the table lock issue that might hit you, an unindexed foreign key is bad in the following cases as well: o When you have an on delete cascade and have not indexed the child table.
http://asktom.oracle.com/pls/ask/f?p=4950:8:::::F4950_P8_DISPLAYID:292016138754   (7646 words)

  
 De-Embedding Foreign Keys, Part 3
Since there are no embedded foreign keys, it has no way to know which relationships are one to one or one to many.
Every SQL statement which uses that foreign key must change because each one explicitly states which table and column contains it; with the movement of the foreign key, those statements become incorrect.
Because it doesn't mention foreign keys, the relationship's semantics are now unbound from its syntax.
http://www.dmreview.com/editorial/newsletter_article.cfm?nl=dmdirect&articleId=2331   (1712 words)

  
 #110 ([PATCH] MySQL InnoDB and use of foreign keys breaks the standard Rakefile) - Ruby on Rails - Trac
After all, if you create a table with a foreign key that references a table that doesn't exist, it only makes sense that the database should throw an error.
itself by doing some checking for Foreign Key definitions and sorting the output of the tables so that either the dependencies are created first, or (prefferably) the Foreign Key definitions are extracted from the Create Table commands and added at the end of the dump via Alter Table commands.
The production database structure dump that is performed when you run rake on a rails project does not output tables in the order needed to satisfy any foreign key definitions when the test database is created.
http://dev.rubyonrails.org/ticket/110   (352 words)

  
 MySQL: InnoDB tables and Foreign Keys
Primary keys are non null values that are used in linking relational tables.
KEY I assume is just declaring another index on the table for faster reads.
You are here: Experts > Computing/Technology > Databases > MySQL > InnoDB tables and Foreign Keys
http://experts.about.com/q/3296/3746534.htm   (308 words)

  
 iAnywhere.com - Managing foreign keys (Sybase Central)
You cannot create a foreign key in a table if the table contains values for the foreign columns that can't be matched to values in the primary table's primary key.
After you have created a foreign key, you can keep track of it on each table's Referencing Tables tab in the right pane; this folder displays any foreign tables that reference the currently selected table.
To display which tables have foreign keys that reference a given table (Sybase Central)
http://www.ianywhere.com/developer/product_manuals/sqlanywhere/0902/en/html/dbugen9/00000052.htm   (281 words)

  
 Define relationships between database tables
In addition, foreign key values can be Null, although the recommendation is that you not leave a foreign key Null without a very specific reason to do so.
Remember, the primary key in the Authors table is a complex key based on both the first and last name fields.
When you move a field to a new table, you'll probably add that new table's primary key to the original table as a foreign key.
http://techrepublic.com.com/5100-10878_11-5141049.html   (1748 words)

  
 dBforums - NULLS - foreign keys
So in those cases where you have bits of information that are more or less accessories to the key, and where a blank value really doesn't have any logical meaning, fine, go with nulls.
I will not have any null values for almost all my attributes in the db apart from these 2 foreign keys.
The problem I have is that I want to avoid using NULL foreign keys (
http://www.dbforums.com/t973503.html   (940 words)

  
 Managing Foreign Keys under SQL Server 6.5 [AVDF Article]
Let's say for example that you have a central table to which several other tables have foreign keys and you want to add a bit field to that table.
The only problem was that I needed to pass a table name to the sp_fkeys stored procedure to get the data about the foreign keys for that table.
I figured the easiest way I could get all the required information about the existing foreign keys was to use the sp_fkeys stored procedure.
http://www.avdf.com/june98/art_ot002.html   (927 words)

  
 Remembering Foreign Keys MySmartChannels
When you try to add a foreign key field(s) to the Journal table (the "One" entity type), you would also have to add additional records (rows) since one journal can have many issues.
For example, in ER Exercise #1, the "Wrote" relationship table will have a Foreign key that will refer back to both Paper and Author.
For example, since one journal can have many issues, the Issue table should have a foreign key that refers back to the Journal entity type.
http://myst-technology.com/mysmartchannels/public/item/59404   (249 words)

  
 Foreign Keys
Because the type of the foreign key is shared amongst several tables those tables must share the same primary key type.
JGenerator supports alien keys by allowing the table name in the relationship modified syntax to be prefixed with a Context name.
These classes can be restricted using a comma seperate list of class names (if they are declared as tables) or fully qualified class names if they are not.
http://www.javelinsoft.com/jgenerator/guide/foreignkeys.html   (1037 words)

  
 [No title]
For example, subjectCode is a foreign key in the Course table that references the Subject table, but it is not the primary key in Course.
For example, headId is a foreign key in Department that references facultyId in Faculty.
    ¡e! f! !!!!!)!!!!!!! !#!!! !ª,g qróÁ%Ÿ¨Foreign Key Discussion, cont.¡&#+#+Ÿ¨©  The referencing relation and the referenced relation may be the same table.
http://www.cs.armstrong.edu/liang/fall2002/csci3720/02slide.ppt   (776 words)

  
 iAnywhere.com - Managing foreign keys (SQL)
For example, the following statement creates the same foreign key as in Example 2, but it defines the foreign key as NOT NULL along with restrictions for when you update or delete.
This example creates a relationship between the skill_id column of the table skill (the foreign table) and the id column of the table contact (the primary table).
A table can only have one primary key defined, but it may have as many foreign keys as necessary.
http://www.ianywhere.com/developer/product_manuals/sqlanywhere/0901/en/html/dbugen9/00000053.htm   (405 words)

  
 Composite foreign keys, Part 2
A disadvantage of non-composite keys, however, is that you lose transitivity.
Also, database queries are executed faster when searching numeric indexes, which most surrogate keys use, than when searching character indexes, which most natural keys would require.
So what you gain in space and simplicity of relationships using non-composite keys, you lose in the complexity of even the simplest queries.
http://expertanswercenter.techtarget.com/eac/knowledgebaseAnswer/0,295199,sid63_gci978175,00.html   (486 words)

  
 More user-friendly foreign keys' support - Iron Speed User Forums
From this customization the problem is solved for the foreign but I am hung up on how to display both.
So if you want your table to be displayed using a set of fields - you'd need to edit the tables referencing it.
This customization is only meant to display foreign key table values - not primary table values?
http://www.websitetoolbox.com/tool/post/ironspeed/vpost?id=51&trail=30   (939 words)

  
 Foreign keys and triggers for referential integrity explained
There is another option to set the foreign key column value to null if the parent row is deleted.
If you want to force a delete behavior other than RESTRICT, CASCADE or SET NULL you would use a trigger.
Is is possible the Erwin created unnecessary triggers?
http://expertanswercenter.techtarget.com/eac/knowledgebaseAnswer/0,295199,sid63_gci978388,00.html   (508 words)

  
 Print - Tips for Using Foreign Keys
However, you might not know that a foreign key can also reference a column that has a unique index.
Also, when you use the sp_help or sp_helpconstraint system stored procedures to investigate the tables' schema, you'll be able to recognize the relationships between tables more easily.
For example, consider tables P and S, which Listing A creates.
http://www.windowsitpro.com/Articles/Print.cfm?ArticleID=25115   (1093 words)

  
 database foreign keys - FutureQuest Community
Think of a user with a userid, and you are counting how many times a user visits a site.
It depends on what you are doing and where you are using them.
an auto_increment id for each table as the primary key.
http://www.aota.net/forums/showthread.php?t=7518   (264 words)

  
 STAF - Primary and Foreign Keys
The reference is not a pointer to a memory address, but rather, the relationship is indicated by the numerical value assigned to the foreign key.
For example, refer to the tcl_tphit and tpt_track tables which contain TPC space points and tracks.
Foreign Key - A variable in a STAF table that refers to a row or set of related rows in the same or in another table.
http://www.star.bnl.gov/~ray/ofl_tut/node14.html   (185 words)

  
 ipedia.com: Data model Article
It furthermore defines a set of specific constraints (candidate keys, foreign keys) and a general language for specifying constraints (first-order logic), and for manipulations and querying the data the relational algebra, tuple calculus and domain calculus are introduced.
An example is the relational model in which all data is represented by mathematical relations (or, to be precise, a slightly generalized version thereof).
Other examples are the Functional Data Model, the Entity-Relationship Model and the Object Role Model although these usually only describe a small subset of the aspects described above.
http://www.ipedia.com/data_model.html   (265 words)

  
 Foreign Keys and mysql
SELECT query, drop the original table and rename the new table to use the old table name then take a deep breath.
The only remedy then is to create a new table do an INSERT..
You need to use InnoDB type tables instead.
http://www.raditha.com/blog/archives/000490.html   (347 words)

  
 Foreign Keys - Neowin.net
My reason for doing this is that i have a list of countries in one table and a list of US states in another, and as everyone registering might not be from the US obviously the state field will contain a null.
and if that is possible, can I have a foreign key which might contain a null?
"Starting from version 3.23.50, InnoDB does not check foreign key constraints on those foreign key or referenced key values which contain a NULL column."
http://www.neowin.net/forum/index.php?showtopic=280665   (416 words)

  
 Fascinating PostgreSQL foreign keys problem - LinuxQuestions.org
In other words, make the table then change it to do something you should be able to do first time round but can't.
Another way is to insert ALL of the attributes into a HUGE parent table and foreign key everything from that!
I've populated the first table but it won't let me populate the foreign-keyed tables - (with the matching data of course).
http://www.linuxquestions.org/questions/showthread.php?postid=39236   (269 words)

  
 WebDeveloper.com - mySQL multiple foreign keys
2) The foreign key syntax goes on the child tables to link up to the parent (which is why you MUST create the parent table first.
I'm trying to create a relational database in mySQL and enforce referential integrity and I need to define two foreign keys in a linking table, ie a table that references two primary keys in two different tables.
I can define one foreign key without a problem but get an error 150 when trying to define multiple foreign keys...
http://www.webdeveloper.com/forum/printthread.php?t=68260   (364 words)

  
 Riccardo Get Detailed Information On Conductor Riccardo Muti And The Orchestra Della Scalla At The Sony Cl
Diego Calvanese, Riccardo Rosati: Anwering Recursive Queries under Keys and Foreign Keys is Undecidable.
List of publications from the DBLP Bibliography Server - FAQ Andrea Calì, Domenico Lembo, Riccardo Rosati, Marco Ruzzi: Experimenting Data Integration with DIS@DIS.
http://www.99hosted.com/names20050.html   (362 words)

  
 MySQL Forums :: Information Schema :: Foreign Keys
Is there likely to be any support for gaining foreign key information directly through the information schema?
Specifically about the referenced table and column(s) of a foreign key !
plz let me know how to link using foreign for this relations, studen versus course, and rest of the options.
http://forums.mysql.com/read.php?101,23447   (583 words)

  
 MySQL 5.0 Reference Manual :: 3.6.6 Using Foreign Keys
This syntax creates a column; it does not create any sort of index or key.
MySQL 5.0 Reference Manual :: 3 Tutorial :: 3.6 Examples of Common Queries :: 3.6.6 Using Foreign Keys
row *************************** Table: shirt Create Table: CREATE TABLE `shirt` (`id` smallint(5) unsigned NOT NULL auto_increment, `style` enum('t-shirt','polo','dress') NOT NULL, `color` enum('red','blue','orange','white','black') NOT NULL, `owner` smallint(5) unsigned NOT NULL, PRIMARY KEY (`id`)) ENGINE=MyISAM DEFAULT CHARSET=latin1
http://dev.mysql.com/doc/mysql/en/example-foreign-keys.html   (322 words)

  
 dBforums - Sequences, Triggers and Foreign Keys - OH MY!
SQL> create table foo_p(foo_p_key number not null constraint pk_foo_p primary key, data1 varchar2(100));
Can anyone give me an example of how I might do this?
dBforums > Database Server Software > Oracle > Sequences, Triggers and Foreign Keys - OH MY!
http://www.dbforums.com/t413819.html   (397 words)

  
 SQL Links -- r937.com
Defines natural key, artificial key, "uniqueifier", surrogate key.
An interesting case study that tries to convince you to break all your simple tables down into a dozen even smaller tables so that you never have to use NULL again.
Longtime 15Seconds discussion list member Tore Bostrup offers valuable advice on designing databases and applications for efficient querying.
http://r937.com/sqllinks.cfm   (3670 words)

  
 Foreign Policy Centre
It is true that political and administrative obstacles to a unified and integrated EU public diplomacy remain but policymakers can, and should, work to remove such obstacles.
He also outlined a series of new policy projects to be undertaken by the FPC, including work on how the UK can make a rapid move toward greater use of renewable energy sources.
Public diplomacy - the activity by which governments seek to communicate and engage with foreign publics - ought to be a priority for EU institutions, but to date strategy and implementation have been disjointed.
http://www.fpc.org.uk/main.html   (3128 words)

  
 Primary and Foreign Keys
The keys will be used as the link to build our relationships between the tables in our relational database.
In each of the tables below, we have included an identifier for each record.
Any time a primary key from one table is found in another table (and it’s not the primary key for that table also), it’s called a foreign key.
http://www.flc.losrios.edu/~davis/Example2.htm   (186 words)

  
 SQL Server Forums at SQLTeam.com - foreign keys
I only want to know if I can create a foreign key of a table to other table.
In order to improve the mind, we ought less to learn than to contemplate.
Don't ALL major 'relational' database vendors support FOREIGN KEYS ?!
http://www.sqlteam.com/Forums/topic.asp?TOPIC_ID=47776   (240 words)

  
 DB: Relationships: Referential Integrity
This only affects the order of entry for many databases, but may be impossible in some, for example in some circular cases where a table refers directly or indirectly to itself.
Options: Block changes, cascading delete, set to NULL, or nothing
clause, in which case the DBMS won't object to foreign keys that have illegal values.
http://www.fredosaurus.com/notes-db/relationships/referential-integrity.html   (643 words)

  
 Data Repositories
Documentation and reports can be used to identify additional information regarding individual attributes, keys, summary levels, frequencies and historical data requirements.
The repository can be used to document the origin and destination of all data elements in the various data models, as well as the business rules that relate to their validation, calculation, transformation, values, etc. Benefits include:
DB2DICT is also a CASE tool that generates SQL code used to create DB2 tables, columns, indexes, views, foreign keys and descriptions.
http://www.usda.gov/da/infores/dataman/dmreport.htm   (4036 words)

  
 /Database/Foreign Keys
Note: Empty foreign keys are allowed even if the target table does not have a matching row.
Adding a foreign key will fail if the source rows do not have matching rows in the target table.
A foreign key consists of one or more columns in one table that uniquely identify a row in another table, i.e.
http://www.suneido.com/suneidoc/Database/Foreign_Keys.htm   (305 words)

  
 DBase - Week 3, Day 2
What are the possible keys in this example?
It is possible for a relation to have serveal possible attributes that could be primary keys.
Foreign keys are added to a relation to show a relationship between two entities.
http://www.rit.edu/~cmd3187/notes/200402/dbase/w3d2.htm   (343 words)

Compwisdom
 About us   |  Why use us?   |  Press   |  Contact us

 Copyright © 2006 CompWisdom.com Usage implies agreement with terms.