Foreign Key Constraint in child table allows to insert values that doesn't exists in the parent table

后端 未结 2 1148
抹茶落季
抹茶落季 2021-01-15 02:00

I am using SQL Server 2012. I have defined a foreign key constraint on a table. The foreign key references composite primary key. The fk constraint does not work when one co

2条回答
  •  时光说笑
    2021-01-15 02:30

    While you really should have provided a complete example as Zohar Peled said, it is likely that your problem lies in the WITH NOCHECK option in the foreign key definition. It should be CHECK to make the foreign key enabled and enforced by the engine. The way it is, the constraint is not trusted.

    See What is lost when I create a Foreign Key using WITH NOCHECK for examples what happens when you use this option.

提交回复
热议问题