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)
 Table Relationships Dependent On Data Value

Author  Topic 

wabs27
Starting Member

4 Posts

Posted - 2007-07-19 : 13:17:12
Hi,

I have a table that contains Customer Information. The Customer table contains a primary key (CustomerID) and then it has a field for CustomerType, and then it has CustomerNumber.

CustomerType can be either a person or a company. Based on the value of CustomerType I would either want the CustomerNumber field of the Customer table to be related to the Person table or the Company table since I store different data for each type of data. How can I get around this issue?

Thanks

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2007-07-19 : 13:27:12
You won't be able to use a foreign key for this. Perhaps you could enforce referential integrity through a trigger, which is typically the alternative when FKs aren't used.


Tara Kizer
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2007-07-19 : 13:45:59
Eliminate the CustomerNumber column, add columns for PersonId and CompanyID, and add FK relationships for those columns. Allow the PersonId and CompanyID columns to be nullable, and add a check constraint to force one or the other to be not null, but not both.


CODO ERGO SUM
Go to Top of Page
   

- Advertisement -