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 now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.