5. Using Constraints to Improve Performance

Simply defined, constraints are rules that a database designer specifies when setting up a table. MySQL enforces these rules when changes are made to information stored in the database. These changes usually occur via INSERT, UPDATE, or DELETE statements, although they can also be triggered by structural alterations to the tables themselves.

MySQL offers the following constraints:

UNIQUEGuarantees that there will be no duplicate values in a column

PRIMARY KEYIdentifies the primary unique identifier of a row

FOREIGN KEYCodifies and enforces the relationships among two or more tables with regard to appropriate behavior when data changes

DEFAULTProvides an automatic value for ...

Get MySQL® Database Design and Tuning now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.