Limit the acceptable range of a value in SQL Server 2008
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)
精彩评论