Are Check Constraints costly?

  • I'm not familiar with how they work.

    I want to apply one to a large table such that:

    If ColA (varchar(3)) <> 'NIB' Then ColB (bit) must = 0, otherwise it can be 1 or 0.

    alter table A

    add constraint X CHECK (CASE WHEN ColA <> 'NIB' THEN 0 ELSE ColB END = ColB)

    Just making sure that this only runs on rows that are about to be updated or inserted and won't slow down those inserts or updates in any meaningful way.

  • No, you won't even notice the difference.

    CHECK constraints can get expensive when built with scalar UDFs with data access. Otherwise, the cost is negligible.

    -- Gianluca Sartori

  • Gianluca Sartori (3/2/2012)


    No, you won't even notice the difference.

    CHECK constraints can get expensive when built with scalar UDFs with data access. Otherwise, the cost is negligible.

    Thank you.

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply