加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MsSql教程 > 正文

sql – 检查所有三列是否为null或null

发布时间:2020-12-12 06:30:43 所属栏目:MsSql教程 来源:网络整理
导读:我有一个有4列的表: create table dbo.Table ( Id int not null,A int null,B int null,C nvarchar (4000) null) 如何确保A,B和C都是三个空或全部三个不为空? 解决方法 你可以设置一个 check constraint : constraint [check_abc] check ( ([A] is null an
我有一个有4列的表:
create table dbo.Table ( 
  Id int not null,A int null,B int null,C nvarchar (4000) null
)

如何确保A,B和C都是三个空或全部三个不为空?

解决方法

你可以设置一个 check constraint
constraint [check_abc] check ( ([A] is null and [B] is null and [C] is null) or
                               ([A] is not null and [B] is not null and [C] is not null) )

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读