C2H50H - 2 months ago 30

SQL Question

How would I go about adding this table constraint in SQL

If C# is BETWEEN 3000 AND 4000 then control has to be less than 60?

`constraint c#_IS check(IF C# BETWEEN 3000 AND 4000 THEN control <= 60)`

Answer

You can phrase it like this:

```
constraint c#_IS check ( (C# NOT BETWEEN 3000 AND 4000) OR (control <= 60) )
```

If you think about the logic, then this does what you want. If `C#`

is not between the limits, then it returns true. But if it is between the limits, then `control`

also has to meet the condition specified.