nikifovadim
nikifovadim

Reputation: 135

Constraint on column to set limit of possible values

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

Upvotes: 0

Views: 585

Answers (1)

Mateen
Mateen

Reputation: 533

You can try this one!

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

Upvotes: 1

Related Questions