Home > database >  Constraint on column to set limit of possible values
Constraint on column to set limit of possible values

Time:02-16

I need to put a constraint on a column so that it can only contain the following range of values

Allowed values: between 1 and 10
Column Data Type: tinyint
DBMS or Docker Image: Microsoft SQL Server - mcr.microsoft.com/mssql/server:2019-latest

I believe it should be something close to this

ALTER TABLE [dbo].[Projects]
ADD CONSTRAINT chk_val_limit CHECK (Priority in (between 1 and 10))
GO

CodePudding user response:

You can try this one!

ALTER TABLE [dbo].[Projects]
ADD CONSTRAINT chk_val_limit CHECK (ColumnName > 1 AND ColumnName < 10)
GO
  • Related