CompTIA DataSys+ (DS0-001)Database Management and MaintenanceMedium
A database administrator needs to ensure that a specific column, `email_address`, in the `Customers` table always contains valid and properly formatted email addresses. They want to prevent insertion or update of any record where the `email_address` does not conform to a standard email pattern (e.g., `name@domain.com`). Which database integrity constraint should be applied to enforce this rule?
- APRIMARY KEY constraint
- BCHECK constraint
- CUNIQUE constraint
- DFOREIGN KEY constraint
Show answer & explanationAnswer & explanation
Correct answer: B. CHECK constraint
A CHECK constraint allows defining a condition that must be true for every row in a table. It is the appropriate constraint to enforce domain integrity, such as validating the format of an email address using a regular expression.
Why the other options are wrong
- A. A PRIMARY KEY constraint uniquely identifies each record and ensures non-null values, but does not validate the format of the data within the column.
- C. A UNIQUE constraint ensures all values in a column are distinct, but does not validate the format of the values.
- D. A FOREIGN KEY constraint maintains referential integrity between tables by linking to a primary key in another table; it does not validate the format of data within a column.
CHECK Constraint
A database constraint that enforces domain integrity by limiting the range of values that can be placed in a column, based on a specified boolean condition.
- Used to validate data format or value ranges.
- Can use SQL functions or regular expressions.
- Applied at the column or table level.
Memory trick: CHECK constraints are the bouncers for data values.