Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need to create a table with two columns having check constraint that Col2 value should be based on the values of Col1. I would like to mention this as below :

if Col1 value is 'A'
then Col2 value should be between 10 and 20

if Col1 value is 'B'
then Col2 value should be between 20 and 30

I know, we can achieve this using triggers. Can we achieve this by declaring a check constraint at table level.

Thank you in advance.
Posted

1 solution

No. A constraint needs to be simpler than that, you're describing rules that need to be checked in code.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900