• No, indexed views does not cut it. You would need a view that performs a UNION ALL of the two tables, but UNION is not a permitted construct in an indexed view.

    What you can do - and which I think is a better option anyway - is to have a supertable that holds the key values. This table could also hold other attributes that are common to external and internal data. To make sure that the same key value is not in both table, you can have type column and there is a trick that I learnt from Joe Celko: have a PK on the key itself, and a UNIQUE constraint on the keycolumn and the type column. Then set up FK constraints in the child tables. The script below illustrates:

    CREATE TABLE keytable (keycol int NOT NULL,

    typecol tinyint NOT NULL

    CONSTRAINT ckc_keytable_typecol CHECK (typecol IN (1, 2)),

    CONSTRAINT pk_keytable PRIMARY KEY (keycol),

    CONSTRAINT u_keytable UNIQUE (keycol, typecol)

    )

    go

    CREATE TABLE externaldata (keycol int NOT NULL,

    typecol tinyint NOT NULL

    CONSTRAINT ckc_externalcol_typecol CHECK (typecol = 1)

    CONSTRAINT def_externalcol_typecol DEFAULT 1,

    othercols nvarchar(200) NULL,

    CONSTRAINT pk_externaldata PRIMARY KEY (keycol),

    CONSTRAINT fk_externaldata_keytable FOREIGN KEY (keycol, typecol)

    REFERENCES keytable (keycol, typecol) ON DELETE CASCADE

    )

    go

    CREATE TABLE internaldata (keycol int NOT NULL,

    typecol tinyint NOT NULL

    CONSTRAINT ckc_internalcol_typecol CHECK (typecol = 2)

    CONSTRAINT def_internalcol_typecol DEFAULT 2,

    othercols nvarchar(200) NULL,

    CONSTRAINT pk_internaldata PRIMARY KEY (keycol),

    CONSTRAINT fk_internaldata_keytable FOREIGN KEY (keycol, typecol)

    REFERENCES keytable (keycol, typecol) ON DELETE CASCADE

    )

    go

    DROP TABLE externaldata, internaldata, keytable

    [font="Times New Roman"]Erland Sommarskog, SQL Server MVP, www.sommarskog.se[/font]