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
DELETE statements, although they can also be triggered by structural alterations to the tables themselves.
MySQL offers the following constraints:
UNIQUE—Guarantees that there will be no duplicate values in a column
PRIMARY KEY—Identifies the primary unique identifier of a row
FOREIGN KEY—Codifies and enforces the relationships among two or more tables with regard to appropriate behavior when data changes
DEFAULT—Provides an automatic value for ...