Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Administration (2000)
 relationship

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2002-05-07 : 11:04:43
tasneem writes "HI
How can I create a relationship between tables in SQL using primary key and forign key,could u give me some examples"

Kevin Snow
Posting Yak Master

149 Posts

Posted - 2002-05-07 : 11:39:51
There's a little help on foreign keys in the TRANSACT SQL Help file found in the Query Analyzer.

Essentially, A foreign key relationship involves two tables. The first table contains a primary key or unique index that will be referenced. The idea is that this key must exist in order for a similar key to be created in the Foreign Key Table.

If you right click on a table in Enterprise Manager, and enter DESIGN mode, you can manage the relationships from the MANAGE RELATIONSHIPS icon. For a NEW key, it allows you to select the Primary Key table (where the key should already exist), and the Foreign key table. THe key may be built on multiple columns(they don't have to have identical column names between the two tables).

You can push or pull this relationship from the Design page of either the PRIMARY KEY TABLE, or the FOREIGN KEY table. When you exit and save the changes, the Enmterprise Manager will alter both tables to establish the relationship. You can select options to enforce the relationship on existing data, or only on new data as it is added to the tables.

Go to Top of Page
   

- Advertisement -