sqlsql-serversql-server-2012constraintsalter-column

how to set maximum length to int data type in sql


ALTER TABLE table_name ALTER COLUMN column_name [int] (4)  NULL;

unable to execute the script, please assist how can I add maximum length to already existed column for an int data type.

enter image description here


Solution

  • If I understand correctly, you want to add a constraint to the column so that it cannot contain a value larger than 9999:

    ALTER TABLE table_name
        ADD CONSTRAINT CK_column_name_RANGE CHECK (column_name >= 0 AND column_name <= 9999)