这样的约束怎么写成? create table table1( c1 int, c2 int, constraint df_c1_c2 check(c2>(case when c1=1 then 5 when c1=2 then 15 end))) 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 我说的是一个例子,可要是复杂的情况怎么办呢?比如:table1c1 int,c2 int要求的约束是:当c1=1 时 c2>5;当c1=2 时 c2>15;c1=3时c2必须能被5整除,怎么写呢? --创建验证函数create function f_check(@c1 int,@c2 int)returns intasbegin if @c1=1 and @c2<=5 return 0 if @c1=2 and @c2<15 return 0 if @c1=3 and @c2%5<>0 return 0 return 1endgocreate table table1( c1 int, c2 int, constraint df_c1_c2 check(dbo.f_check(c1,c2)>0)) 简单列变行(把列按照关键字插入一样,其他不变) 急解!!!!!SQL 配置管理器 出错 MSDE是不是完全免费 如何用T-sql 计算出 sql 语句执行时间? 我的表有多个索引, 请问执行下面的语句时, 系统到底用哪一个索引? 为什么要使用存储过程? 数据库设计 高手来加点油 当场给分 sqlserver触发器 在PowerDesigner9中如何为字段设置默认值为Getdate()以及其他MSSql的函数?? 极菜问题,表中建立了主键,是否还需要建立索引?如下 表中数据排序问题 sql重复记录查找问题,请高手进(在线等..解决就结贴)
比如:
table1
c1 int,
c2 int
要求的约束是:当c1=1 时 c2>5;当c1=2 时 c2>15;c1=3时c2必须能被5整除,怎么写呢?
create function f_check(@c1 int,@c2 int)
returns int
as
begin
if @c1=1 and @c2<=5
return 0
if @c1=2 and @c2<15
return 0 if @c1=3 and @c2%5<>0
return 0 return 1
end
gocreate table table1
(
c1 int,
c2 int,
constraint df_c1_c2 check(dbo.f_check(c1,c2)>0)
)