This works:drop table test1drop table test2drop table test3drop view vwtestcreate table test1 (ID int not null, date datetime not null, number int not null)create table test2 (ID int not null, date datetime not null, number int not null)create table test3 (ID int not null, date datetime not null, number int not null)gocreate view vwtestasselect * from test1union allselect * from test2union allselect * from test3goalter table test1add constraint pk_test1a primary key (id,number) alter table test2add constraint pk_test2a primary key (id,number) alter table test3add constraint pk_test3a primary key (id,number) goalter table test1add constraint ck_test1a check (number = 1) alter table test2add constraint ck_test2a check (number = 2) alter table test3add constraint ck_test3a check (number = 3) goinsert into vwtestselect 2, current_timestamp, 1go
When I change the CHECK to include a function, it doesn't work:create table test1 (ID int not null, date datetime not null, number int not null)create table test2 (ID int not null, date datetime not null, number int not null)create table test3 (ID int not null, date datetime not null, number int not null)gocreate view vwtestasselect * from test1union allselect * from test2union allselect * from test3goalter table test1add constraint pk_test1a primary key (id,date) alter table test2add constraint pk_test2a primary key (id,date) alter table test3add constraint pk_test3a primary key (id,date) goalter table test1add constraint ck_test1 check (crdm.fnGetPartitionNumberForDate(Date) = 1) alter table test2add constraint ck_test2 check (crdm.fnGetPartitionNumberForDate(Date) = 2) alter table test3add constraint ck_test3 check (crdm.fnGetPartitionNumberForDate(Date) = 3) goinsert into vwtestselect 2, current_timestamp, 1go
Can anyone explain why this is?Hearty head pats