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 IntegrityOver the following sections, we'll discuss how to use constraints and triggers, which areusually the preferred ways to protect data integrity.Enforcing Data Integrity in ConstraintsIt is well known that using constraints is the most reliable way to enforce data integrityrules. So how do we go about enforcing our previous business rule (the height of a boxmust be less than, or equal to, the width; and the width must be less than, or equal to,the length) in a constraint?Our first attempt might look as shown in Listing 6-4.ALTER TABLE dbo.BoxesADD CONSTRAINT Boxes_ConsistentDimensionsCHECK(HeightInInches

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

Saved successfully!

Ooh no, something went wrong!