If I get what you need, you need to have a primary key on A in table Y and a unique constraint on A, B in table Y.
Try the following:
create table Y ( A int not null, B int not null, primary key (A) ); create unique index IX_Y_AB on Y(A, B); create table X ( A int not null, B int not null, C int null, primary key (A, B), foreign key (A) references Y(A), foreign key (A, C) references Y(A, B) );
Test:
insert into Y values (1, 2) insert into X values (1, 1, null)
source share