How to set range for int in sql server

range, sql-server

Solution

There is no INT(5) data type in sql server , but you can make use of CHECK constraints to put a limit/Range on values that can be inserted in that column.

Google to learn more about Check Constraint and you would do something like this.....

CREATE TABLE MyTable
(
    Testing  INT CHECK (testing > 100 AND testing <500)
  , OtherCol INT 
);

Problem

hey I'm new in SQL server i was wondering if we can set range to int (when creating table) like we set range to char ``` testing char(5) not null ``` when i tried to use the same way to set range in int ``` testing int(5) not null ``` it will get error, so how to set range for int. if can't can you tell me why?

Original source