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
 two nulls

Author  Topic 

jamesdwhite
Starting Member

9 Posts

Posted - 2007-02-09 : 12:24:50
Hi

i have a table t1 and wish to have to fk's now i want to be able to set it up so that only one of them can be null example:

t1
id___________fk1________fk2

1____________6__________NULL
2____________NULL_______3
3____________7__________NULL
4____________NULL_______NULL <<<<<<< This should not be allowed

thanks
james

X002548
Not Just a Number

15586 Posts

Posted - 2007-02-09 : 12:33:05
You'd need to use a trigger



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

rockmoose
SQL Natt Alfen

3279 Posts

Posted - 2007-02-09 : 15:35:01
What about a check constraint;

alter table ... add constraint CHK_oneMustBeNull check(coalesce(fk1,fk2) is not null and (fk1 is null or fk2 is null))

rockmoose
Go to Top of Page
   

- Advertisement -