Question

I want to define a tinyint with an accepted range of 0 - 10. I know how to use triggers to validate a column and achieve this effect.

However, is it possible to create a user-defined data type that specifies this range as a rule? Then, if a value outside of range is attempted, of course an error would be thrown automatically, without the need of triggers?

Was it helpful?

Solution

Use a CHECK constraint rather than user defined types which are quite awkward to use

OTHER TIPS

First, create a rule with your constraint, then a type, then associate it:

http://www.mssqltips.com/tip.asp?tip=1628

(But I agree with gbn, 99.99% of the time, just use a check constraint)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top