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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 7: Advanced Use of ConstraintsVALUES ( 1 ,1 ,'Cannot print TPS report' ,'Active' ,'Active') ;Msg 547, Level 16, State 0, Line 1The INSERT statement conflicted with the FOREIGN KEYconstraint "FK_Tickets_Developers_WithStatus". The conflictoccurred in database "test2", table "dbo.Developers".The statement has been terminated.Listing 7-8: The DeveloperStatus must match the Status of theassigned developer.Listing 7-9 shows that we can add a closed ticket, but cannot reopen it, while thedeveloper is still on vacation.INSERT INTO dbo.Tickets( TicketID ,AssignedToDeveloperID ,Description ,TicketStatus,DeveloperStatus)VALUES ( 1 ,1 ,'Cannot print TPS report' ,'Closed' ,'Vacation') ;(1 row(s) affected)UPDATE dbo.TicketsSET TicketStatus = 'Active'216

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

Saved successfully!

Ooh no, something went wrong!