locked
How to update table with NULL if not in domain table RRS feed

  • Question

  • User-1188570427 posted

    Is there a way to update a table that has a FK to a domain table if the Value IS NOT found in the domain table?

    This column allows Nulls OR has to be in a domain table.  If I take legacy data from one column to put it in a new column, I want to force a NULL value if it isn't found in the Domain table. Is there a way to run one update statement and it do that so it doesn't error out on each one that needs a null value?

    OR do I need to turn off the FK connection and then turn it back on AFTER I move all the data like I want etc?

    Thanks.

    Friday, November 13, 2015 5:31 AM

Answers

  • User364663285 posted

    You can't as the FK must exist within its parent table as one PK of the table, which also does not allow NULL values.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, November 13, 2015 10:18 AM
  • User77042963 posted

    You just need to set your foreign key column NULLABLE to accept null values.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, November 13, 2015 11:23 AM

All replies

  • User364663285 posted

    You can't as the FK must exist within its parent table as one PK of the table, which also does not allow NULL values.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, November 13, 2015 10:18 AM
  • User77042963 posted

    You just need to set your foreign key column NULLABLE to accept null values.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, November 13, 2015 11:23 AM