能否建立这样的约束?

happywwh 2003-10-28 11:07:54
table1(a,b,c,d)
能否约束同一记录中列b和列c中只出现一个值,即:要么b有值,c为空,要么b为空,c有值。
...全文
38 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
eddiezhuo 2003-10-28
  • 打赏
  • 举报
回复
create table t(a int,b int check( not exists (a is null and b is null) )
sai1691 2003-10-28
  • 打赏
  • 举报
回复
create table table1(a int,b int check( (b is not null and c is null) or (b is null and c is not null) ) ,d int)
txlicenhe 2003-10-28
  • 打赏
  • 举报
回复
alter table table1 add constraint ck_1 check((b is null and c is not null) or (b is not null and c is null))
pengdali 2003-10-28
  • 打赏
  • 举报
回复
create table table1(a int,b int check( (b is not null and c is null) or (b is null and c is not null) ) )
gmlxf 2003-10-28
  • 打赏
  • 举报
回复
alter table table1 with nocheck add constraint c_check check((b is null and c is not null) or (b is not null and c is null))
gmlxf 2003-10-28
  • 打赏
  • 举报
回复
create table #table1(
a int,
b int,
c int,
d int,
check((b is not null and c is null) or (b is null and c is not null)))

insert #table1 values(1,2,null,4) -- ok
insert #table1 values(1,null,3,4) -- ok
insert #table1 values(1,null,null,4) -- error
insert #table1 values(1,2,3,4) -- error

drop table #table1

34,874

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧