社区
MS-SQL Server
帖子详情
能否建立这样的约束?
happywwh
2003-10-28 11:07:54
table1(a,b,c,d)
能否约束同一记录中列b和列c中只出现一个值,即:要么b有值,c为空,要么b为空,c有值。
...全文
38
6
打赏
收藏
能否建立这样的约束?
table1(a,b,c,d) 能否约束同一记录中列b和列c中只出现一个值,即:要么b有值,c为空,要么b为空,c有值。
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用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
什么叫主键
约束
?怎样实现Mysql主键
约束
?
主键
约束
相当于唯一
约束
+非空
约束
的组合,主键
约束
列不允许重复,也不允许出现空值。主键
约束
的关键字是primary key,当创建主键的
约束
时,系统默认会在所在的列和列组合上
建立
对应的唯一索引。一张表只能有一个主键...
数据库中的表如何设置
约束
?(精简版)
什么是主键?什么是外键?什么是唯一
约束
?如何自增,如何........
在mysql如何添加
约束
条件_mysql怎么添加
约束
?
在MYSQL数据库中,建表时就可以进行对表的各项进行一些操作,例如添加主键
约束
或者非空
约束
;也可以在建表后进行添加
约束
和删除
约束
的操作。下面本篇文章就来带大家具体了解一下,希望对大家有所帮助。什么是
约束
?...
外键——如何在表中
建立
外键
约束
?
建表时创建外键
约束
create table 表名(列名 数据类型 foreign key references 外表名(主键),列名 数据类型) 建表后创建外键
约束
alter table 表名 add constraint fk_表名 foreign key(列名) references 外表名...
MySQL数据库如何添加和删除
约束
?如何查看
约束
名?
MySQL中有6种常见的
约束
:主键
约束
(primary key)、外键
约束
(foreign key)、非空
约束
(not null)、唯一性
约束
(unique)、默认值
约束
(default)以及自增
约束
(auto_increment),以下是添加和删除这几种
约束
的...
MS-SQL Server
34,874
社区成员
254,639
社区内容
发帖
与我相关
我的任务
MS-SQL Server
MS-SQL Server相关内容讨论专区
复制链接
扫一扫
分享
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章