SQL约束minvalue / maxvalue? [英] SQL constraint minvalue / maxvalue?

查看:235
本文介绍了SQL约束minvalue / maxvalue?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一种方法可以为数字字段设置SQL约束,最小值应为1234,最大值应为4523?

解决方案

检查的SQL Server语法code>约束

 创建表号(
number int not null
check(number> = 1234 and number< = 4523),
...


创建表号(
number int not null,
check(number> = 1234 and number< = 4523),
...


创建表号(
number int not null ,
constraint number_range_check
check(number> = 1234 and number< = 4523),
...

/ pre>

Is there a way to set a SQL constraint for a numeric field that min value should be 1234 and max value should be 4523?

解决方案

SQL Server syntax for the check constraint:

create table numbers (
    number int not null
        check(number >= 1234 and number <= 4523),
    ...
)

create table numbers (
    number int not null,
    check(number >= 1234 and number <= 4523),
    ...
)

create table numbers (
    number int not null,
    constraint number_range_check
        check(number >= 1234 and number <= 4523),
    ...
)

这篇关于SQL约束minvalue / maxvalue?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆