Does SQL Server allow constraint violations in a transaction as long as it's not committed yet?

后端 未结 4 866
后悔当初
后悔当初 2020-12-14 15:00

Does SQL Server allow constraint violations (i.e. deferred constraints) in a transaction as long as the transaction has not been committed yet?

I ha

4条回答
  •  生来不讨喜
    2020-12-14 15:38

    You can disable your constraints while running your transaction, and then reenabling them when you are done.

    ALTER TABLE mytable NOCHECK CONSTRAINT myconstraint
    
    --... RUN TRANSACTION
    
    ALTER TABLE mytable WITH CHECK CHECK CONTRAINT ALL
    

    Warning: This will affect all connections.

提交回复
热议问题