• Because Id value 4 is not exits in t2 table. Thats why you getting error.

    If you have foreign key then the reference column value must exists in parent table.

    below code will work.

    create table t1

    (

    ID int primary key identity(1,1),

    Name varchar(100)

    )

    Create table T2

    (

    ID2 int primary key identity(1,1),

    Name2 varchar(100)

    )

    Insert into T1 values('A'),('B'),('E'),('G')

    INsERT INTO T2 values ('L'),('K'),('M'),('S')

    Create table t3

    (

    ID3 int,

    Name3 varchar(100)

    )

    alter table t3

    ADD constraint FK_ID4 foreign key (ID3) references t1(ID)

    alter table t3

    ADD constraint FK_ID3 foreign key (ID3) references t2(ID2)

    Insert into t3 values (4,'G')

    drop table t3

    drop table t2

    drop table t1

    Malleswarareddy
    I.T.Analyst
    MCITP(70-451)