22,301
社区成员




create table test(a int, b int, c as a - b)
go
alter table test add constraint chk_a check (a>=b)
go
insert into test(a,b) values(100,80)
go
insert into test(a,b) values(80,80)
go
insert into test(a,b) values(80,100)
go
select * from test
go
drop table test
go
(1 行受影响)
(1 行受影响)
消息 547,级别 16,状态 0,第 1 行
INSERT 语句与 CHECK 约束"chk_a"冲突。该冲突发生于数据库"test",表"dbo.test"。
语句已终止。
a b c
----------- ----------- -----------
100 80 20
80 80 0
(2 行受影响)
但是要允许0的情况啊[/quote]
create table test(a int, b int, c as a - b)
go
alter table test add constraint chk_a check (a>b)
go
insert into test(a,b) values(100,80)
go
insert into test(a,b) values(80,80)
go
select * from test
go
drop table test
go
(1 行受影响)
消息 547,级别 16,状态 0,第 1 行
INSERT 语句与 CHECK 约束"chk_a"冲突。该冲突发生于数据库"test",表"dbo.test"。
语句已终止。
a b c
----------- ----------- -----------
100 80 20
(1 行受影响)
CREATE TABLE Tab12(a INT,b INT,c AS a-b PERSISTED)
ALTER TABLE Tab12 ADD CONSTRAINT CHK_Tab12 CHECK(c>=0);
INSERT INTO Tab12(a,b)VALUES(1,2);
/*
消息 547,级别 16,状态 0,第 4 行
INSERT 语句与 CHECK 约束"CHK_Tab12"冲突。.....
语句已终止。
*/
DROP TABLE Tab12