SQL限制数据库中的最小值和最大值

时间:2022-09-26 18:49:29
CREATE TABLE TBL_CD(
CDnr                int identity(1,1),
CDTitel             nvarchar(80) NOT NULL,
CDduur              int,
CDprijs             smallmoney,

So I am creating this table, is there any way I can limit the value of CDprijs to be between 0 and 100?

所以我正在创建这个表,有什么办法可以将CDprijs的值限制在0到100之间吗?

1 个解决方案

#1


8  

Add a check constraint:

添加检查约束:

CREATE TABLE TBL_CD(
CDnr                int identity(1,1),
CDTitel             nvarchar(80) NOT NULL,
CDduur              int,
CDprijs             smallmoney,
check (CDprijs between 0 and 100),

#1


8  

Add a check constraint:

添加检查约束:

CREATE TABLE TBL_CD(
CDnr                int identity(1,1),
CDTitel             nvarchar(80) NOT NULL,
CDduur              int,
CDprijs             smallmoney,
check (CDprijs between 0 and 100),