문제

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?

도움이 되었습니까?

해결책

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

다른 팁

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)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top