Posted on 2013-12-11
This is more a question to make sure I am doing this right.
I have a table, let's call it "clicks"
click_id int PK
I am trying to correct an error from a previous time where the product_id was set to default to zero. I have a table of "products" and need to set the product_id to a null default in "clicks", remove the default constraint of 0 from "clicks" and then foreign key product_id in "clicks" to product_id in "products".
All is well with removing the constraint. However, I have 50,000,000 rows of "clicks" historical data with a 0 in the product_id. The job of sanitizing this data to update all the 0's to null is too big for now.
Question - If I create the FK with a NOCHECK Constraint would I have the correct FK structure going forward and have the DB basically ignore the legacy data (for now)?
Later, I can run the scripts to fix the legacy data and then alter the FK to be correct and check the constraint.
Am I on the right path?