Board index » delphi » Constraint Question

Constraint Question

Hi,
What is the best way to create a constraint (MS SQL 6.5), which
validates the field(s) in question against a primary key in another
table, BUT allows null values as well?
Does this need to be done in a trigger, or is there some way to do it in
a constraint?
Thanks,
Randall Klein
Randa...@VersaLogic.com
 

Re:Constraint Question


If you just want to validate that the column entered exists as a key on the
second table, use declarative RI, i.e., define the column as a foreign key:

create table mytable1 (
  mycol varchar (10) null,
  constraint myconstr foreign key
 ( mycol ) references mytable2 ( keycol )
)

As long as you define mycol as null, you should be OK.

--jd

Quote
Randall Klein wrote in message <36EFF529.72A64...@VersaLogic.com>...
>Hi,
>What is the best way to create a constraint (MS SQL 6.5), which
>validates the field(s) in question against a primary key in another
>table, BUT allows null values as well?
>Does this need to be done in a trigger, or is there some way to do it in
>a constraint?
>Thanks,
>Randall Klein
>Randa...@VersaLogic.com

Other Threads