Connecting Tech Pros Worldwide Forums | Help | Site Map

Foreign key constraints

Newbie
 
Join Date: Nov 2008
Posts: 1
#1: Nov 16 '08
Hi

I'm developing a DB using SQL server 2005 to b used in a data mining project, the data that will be worked with are constant and would not change or updated and more records will be add later. I created the tables and the relationship between them using the Database diagrams without writing any code.

I noticed that errors occurs in the data entry step so i changed a field value in the relationship dialoug box which is : "Enforce foreign key constraints" when i change the value to "No" the data entry process done smoothly.

I need to know wt does this field do? and if changing the values will effects the database.

Thanks alot,

Regards
Noora

Delerna's Avatar
Expert
 
Join Date: Jan 2008
Location: Sydney
Posts: 790
#2: Nov 19 '08

re: Foreign key constraints


Basically.....

Primary keys are used to uniquely reference any single record within a single table.

A foreign key is used to relate records in one table with records in another table.

A foreign key constraint ensures that you cannot have records in one table that do not have at least 1 related record in the other.

For example, you have an order header table and an order line table.
The order number might be the foreign key between the two tables

The foreign key constraint would ensure that you cannot have records in the order lines table for an order number that does not exist in the order header table.

Does that make sense?
Can you see now what you have done by turning the constraint off?

Regards
Reply