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 Development (2000)
 Foreign Key - Best practices

Author  Topic 

t1g312
Posting Yak Master

148 Posts

Posted - 2004-08-08 : 01:07:55
Hi all,

Suppose I have a parent table with a 2 field primary key. Which one of the following would be the right way of creating a foreign key in a child table -
a) Create two fields in the child table which hold the primary key field values
b) Create a rowid in the parent table and use that as the foreign key in the child table.

Thanks in advance,
Adi

Adi

-------------------------
/me sux @sql server

mohdowais
Sheikh of Yak Knowledge

1456 Posts

Posted - 2004-08-08 : 02:47:56
Definitely go with the first, unless you have a good reason not to. Like ending up with a six column primary key, for example!

General rule is to use natural primary keys as far as possible. While IDENTITY columns might make development easier, you might just end up with a lot of bad data.

OS
Go to Top of Page

t1g312
Posting Yak Master

148 Posts

Posted - 2004-08-08 : 03:29:01
Thanks again OS!

Adi

-------------------------
/me sux @sql server
Go to Top of Page
   

- Advertisement -