I have done the above by using the following, but it costs much.
create table sample(id int primary key)
create table sample2(id int primary key)
create view sampleall
As
select id from sample
union
select id from sample2
Create FUNCTION dbo.CheckFunction (@ID INT)
RETURNS BIT AS
BEGIN
IF EXISTS (SELECT 1 FROM sampleall WHERE id = @ID)
BEGIN
RETURN 1;
END
RETURN 0;
END
CREATE TABLE sample3 (ID INT NOT NULL CONSTRAINT CHK_ID CHECK (dbo.CheckFunction(ID) = 1))