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 6: Common Problems with Data IntegrityVALUES ('Tent','Camping Gear',20) ;Listing 6-17: Populating Boxes and Items tables with valid test data.Listing 6-18 confirms that the constraint prevents invalid data from saving.INSERT INTO dbo.Items(ItemLabel,BoxLabel,WeightInPounds)VALUES ('Yoga mat','No Such Box',2) ;Msg 547, Level 16, State 0, Line 1The INSERT statement conflicted with the FOREIGN KEYconstraint "FK_Items_Boxes". The conflict occurred indatabase "TEST", table "dbo.Boxes", column 'BoxLabel'.The statement has been terminated.Listing 6-18: FK_Items_Boxes prohibits orphan rows.Disabled constraints do…nothingSay we need to bulk load data into these two tables, and that the loading must completeas quickly as possible; this is a very common requirement. Assuming we know that thedata comes from a trusted source, and that all the data in that source is clean, it is quitea common practice to disable the FOREIGN KEY constraint, so that we can start loading175

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

Saved successfully!

Ooh no, something went wrong!