Home Forums SQL Server 2005 T-SQL (SS2K5) Referential Integrity - how to avoid errors so I can automate manual process - vendor code RE: Referential Integrity - how to avoid errors so I can automate manual process - vendor code

  • Are there dangers with dropping constraints, running an insert statement, then adding the constraint again?

    Yes. If you're doing this because the data you want to insert violates the constraints, you're not going to be able to add the constraints back on at the end again. You'll get an error message telling you that the constraint can't be created because there's already data that violates it.

    Constraints are there for a reason. They shouldn't be ignored because they're inconvenient. You should ask your vendor instead to include an existence test in the script. They could use the MERGE statement instead, but only on SQL Server 2008 or later.

    John