17.07.2015 Views

Defensive Database Programming - Red Gate Software

Defensive Database Programming - Red Gate Software

Defensive Database Programming - Red Gate Software

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 7: Advanced Use of ConstraintsINSERT INTO dbo.InventoryLog( ItemID ,ChangeDate ,ChangeQuantity ,CurrentQuantity ,PreviousChangeDate ,PreviousQuantity)VALUES ( 2 ,'20100102' ,-2 ,1 , -- CurrentQuantity should be 3'20100101' ,5);Msg 547, Level 16, State 0, Line 1The INSERT statement conflicted with the CHECK constraint"CHK_InventoryLog_ValidChange". The conflict occurred indatabase "test2", table "dbo.InventoryLog".The statement has been terminated.INSERT INTO dbo.InventoryLog( ItemID ,ChangeDate ,ChangeQuantity ,CurrentQuantity ,PreviousChangeDate ,PreviousQuantity)VALUES ( 2 ,'20100102' ,-2 ,1 ,'20100101' ,3 -- PreviousQuantity should be 5);239

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!