Quantcast
Channel: SQL Server Database Engine forum
Viewing all articles
Browse latest Browse all 12963

Conditional Foregin Key constraint

$
0
0

I am trying to implement a check constraint (since Conditional Foreign keys are not possible).

In my table, column REFDCD should either be blank or should be found in the Primary Key (DLR_CODE) of the same table.

I tried :

alter table dist_mas add
check (refdcd in (select distinct dlr_code from dist_mas))

But subqueries are not allowed in Check constraints.

Can someone guide me?

Thanks

Mohan


MohanSQL



Viewing all articles
Browse latest Browse all 12963

Trending Articles