question

khalil123456 avatar image
khalil123456 asked

How do I build a constraint that depends on another column - SQL 2000

I want to make a constraint (if one field is not null, the end user must put 3 or 5 or 10 in another field) and the two fields are in the same table. To put it another way, if the end user puts any value in field A, I also want them to put specified values in field B? Can any one help me please? Thanks for help
sql-server-2000constraintanalysis
10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

· Write an Answer
Magnus Ahlkvist avatar image
Magnus Ahlkvist answered
ALTER TABLE ADD CONSTRAINT CK_IF_A_THEN_B CHECK ((A IS NULL) OR (B IN (3,5,10)));
1 comment
10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

@khalil123456 If Magnus's response answer's your question, please mark it as your selected answer for the benefit of other users.
0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.