17.06.2013 Views

Beginning Microsoft SQL Server 2008 ... - S3 Tech Training

Beginning Microsoft SQL Server 2008 ... - S3 Tech Training

Beginning Microsoft SQL Server 2008 ... - S3 Tech Training

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 8: Being Normal: Normalization and Other Basic Design Issues<br />

Figure 8-31<br />

Adding Some Constraints<br />

258<br />

As we were going through the building of our tables and relationships, I mentioned a requirement that<br />

we still haven’t addressed. This requirement needs a constraint to enforce it: the part number is formatted<br />

as 9A9999 where “9” indicates a numeric digit 0–9 and “A” indicates an alpha (non-numeric) character.<br />

Let’s add that requirement now by right-clicking the Products table and selecting Check Constraints to<br />

bring up the dialog shown in Figure 8-32.<br />

Figure 8-32<br />

It is at this point that we are ready to click Add and define our constraint. To restrict part numbers<br />

entered to the format we’ve established, we’re going to need to make use of the LIKE operator:<br />

(PartNo LIKE ‘[0-9][A-Z][0-9][0-9][0-9][0-9]’)

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

Saved successfully!

Ooh no, something went wrong!