what is for foreign key ??
Answer Posted / akhtar mohammad kalim
A foreign key is a field (or fields) that points to the
primary key of another table. The purpose of the foreign
key is to ensure referential integrity of the data. In
other words, only values that are supposed to appear in the
database are permitted.
For example, say we have two tables, a CUSTOMER table that
includes all customer data, and an ORDERS table that
includes all customer orders. The constraint here is that
all orders must be associated with a customer that is
already in the CUSTOMER table. In this case, we will place
a foreign key on the ORDERS table and have it relate to the
primary key of the CUSTOMER table. This way, we can ensure
that all orders in the ORDERS table are related to a
customer in the CUSTOMER table. In other words, the ORDERS
table cannot contain information on a customer that is not
in the CUSTOMER table.
The structure of these two tables will be as follows:
Table CUSTOMER column name characteristic
SID Primary Key
Last_Name
First_Name
Table ORDERS column name characteristic
Order_ID Primary Key
Order_Date
Customer_SID Foreign Key
Amount
In the above example, the Customer_SID column in the ORDERS
table is a foreign key pointing to the SID column in the
CUSTOMER table.
| Is This Answer Correct ? | 9 Yes | 1 No |
Post New Answer View All Answers
How do you maintain database integrity where deletions from one table will automatically cause deletions in another table?
How to query multiple tables jointly?
How to add the custom code in Report?
What do you mean by an execution plan? Why is it used?
what are different types of backups available in sql server? : Sql server database administration
what is a live lock? : Sql server database administration
What are the new data types are introduced in sql 2000?
Why should one not prefix user stored procedures with ‘sp_’?
What will be the maximum number of index per table?
What is a hint?
What is an active database?
What stored by the master?
What is triggers and stored procedures?
What changes in the front end code is needed if mirroring is implemented for the high availability? : sql server database administration
What is a dataset and what are the different types of datasets?