sql - 检查所有三列是否不为空或为空

标签 sql sql-server null sql-server-2012 check-constraints

我有一个包含 4 列的表格:

create table dbo.Table ( 
  Id int not null,
  A int null,
  B int null,   
  C nvarchar (4000) null
)

如何确保 ABC 全部为三个 null 或全部三个 不为空

最佳答案

您可以设置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) )

关于sql - 检查所有三列是否不为空或为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29846448/

相关文章:

java - String.valueOf(String Object) 的 null 和 "null"有什么区别

android - 尝试在安卓手机上设置屏幕亮度

c# - 从 nvarchar 值到数据类型 int 的转换失败?

SQL Server 到 MYSQL 迁移工具

php - MySQL插入语句不会插入?

SQL计算净容量

c# - 编码 xml 并保存到 SQL Server

java - 从文件构建数组中的 NullPointerException

mysql - SQL - 如何按公共(public)列对多个表进行排序

sql - 执行真实计划SQL Server