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
 General SQL Server Forums
 New to SQL Server Programming
 Tables Relationship

Author  Topic 

j0shua
Starting Member

40 Posts

Posted - 2009-03-25 : 05:39:01
Hi there, i have been assigned to an existing database that is being used in a software. I check the tables and found out that there are tables whose relationship is not based on foreign keys and primary keys. The tables are connected through a common field. What is the effect of this in the long run? how can i edit this safely without any side effect on the current database? thank you. help is very much appreciated.

RickD
Slow But Sure Yak Herding Master

3608 Posts

Posted - 2009-03-25 : 06:50:23
Does every row join between the tables? Are there nulls on either side?

There are lots of fields in databases that are logically foreign keys, but can't be created as such due to reasons like nullability.

If there are no nulls, you can create a foreign key as long as you're 100% sure it is a true foreign key.
Go to Top of Page

j0shua
Starting Member

40 Posts

Posted - 2009-03-25 : 07:11:38
thank you. is the foreign key must be a primary key on the other table?
Go to Top of Page

RickD
Slow But Sure Yak Herding Master

3608 Posts

Posted - 2009-03-25 : 09:14:50
Yes, it must always exist as a primary key on another table.
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2009-03-25 : 12:45:16
Technically it just needs to have a unique constraint, it doesn't have to be the primary key.
Go to Top of Page
   

- Advertisement -