Foreign Key is a column or combination of column that is
used to establish and reference a link
between the data in a two tables. A Foreign Key Constraints enforces this referential
integrity. A Foreign Key Constraint defines a reference to a column
with a Primary key or UNIQUE constraints in the same, or another table.The values in the foreign key column must appear in the
primary key column.
Consider the following facts before you implement a FOREIGN
KEY Constraints
- A FOREIGN KEY Constraints provides single column or multicolumn referential integrity. The number of columns and the data types that are specified in the FOREIGN KEY statement must match the number of columns and data types in the REFERENCES clause.
- Unlikely PRIMARY KEY or UNQUE Constraints, FOREIGN KEY constraints do not create indexes automatically.
- A FOREIGN KEY Constraint that uses only the references clause with out the FOREIGN KEY clause refers to a column in the same table.
When to use FOREIGN KEY Constraints
- The data in one or more columns can hold only values contained in certain columns in the same or another table.
- The row in a table should be declared while rows in another table depend on them.
No comments :
Post a Comment