Search code examples
sql-serversql-server-2008validationuser-defined-types

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?


Solution

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