Home Forums SQL Server 2005 Administering FK created WITH NOCHECK, FK validation for SQL update statements which don't update FK column(s) RE: FK created WITH NOCHECK, FK validation for SQL update statements which don't update FK column(s)

  • Not sure if there was a misconception but to clarify the WITH NOCHECK option only applies to the initial creation of the FK, not later updates. If the column with the FK constraint is later updated, the FK is checked. As to whether "later updates" also mean when the table us updated but the column with the constraint is not updated, no. If you're not updating the column with the FK constraint then the constraint is not checked again.

    use tempdb;

    go

    create table dbo.test

    (

    test_id int identity(1,1) not null primary key,

    name varchar(100)

    );

    create table dbo.test_child

    (

    test_child_id int identity(1,1) not null primary key,

    test_id int null,

    name varchar(100)

    );

    insert into dbo.test_child (test_id, name) values (1,'John');

    alter table dbo.test_child with nocheck add constraint [fk_dbo.test_child_dbo.test.test_id] foreign key (test_id)

    references dbo.test (test_id) ;

    -- would not succeed if FK were checked

    update dbo.test_child

    set name = 'Dave'

    where name = 'John';

    Chances are your CPU is issue is related to something else. It could be a lot of things but if you post the actual execution plan from the update it may give us some things to look into further.

    There are no special teachers of virtue, because virtue is taught by the whole community.
    --Plato