Q1
True / FalseMySQL enforces the CHECK constraint in the same way it enforces the NOT NULL constraint.
MySQL recognizes the CHECK constraint syntax, but it does not enforce the constraint in versions before 8.0.16.
Q2
True / FalseYou can use the CHECK constraint in a MySQL CREATE TABLE statement.
The syntax for the CHECK constraint can be included in the CREATE TABLE statement, but it is not enforced in versions before 8.0.16.
Q3
True / FalseThe CHECK constraint in MySQL is used to limit the values that can be placed in a column.
The purpose of the CHECK constraint is to ensure that all values in a column satisfy certain conditions.
Q4
True / FalseMySQL fully supports and enforces the CHECK constraint starting from version 5.7.
MySQL started enforcing the CHECK constraint from version 8.0.16 onwards, not in version 5.7.
Q5
True / FalseIn MySQL, the CHECK constraint can reference multiple columns in the same table.
The CHECK constraint can reference more than one column in the table to enforce more complex conditions.
Q6
True / FalseIn MySQL, you can add a CHECK constraint to an existing table using the ALTER TABLE statement.
You can add a CHECK constraint to an existing table using the ALTER TABLE statement, but enforcement of the constraint depends on the MySQL version.
Q7
True / FalseIn MySQL, you can create a CHECK constraint that uses subqueries.
MySQL does not support subqueries in the CHECK constraint expressions.
Q8
True / FalseThe CHECK constraint in MySQL can be used to enforce domain integrity by ensuring that only valid domain values are entered into a column.
The CHECK constraint is designed to enforce domain integrity by restricting the values that can be entered into a column based on specified criteria.
Q9
True / FalseIn MySQL, a CHECK constraint can reference another table to ensure referential integrity.
CHECK constraints cannot reference other tables; they can only apply to the current table's columns.
Q10
True / FalseAs of MySQL 8.0.16, the CHECK constraint is both recognized and enforced, allowing for more robust data validation within the database.
Starting with MySQL 8.0.16, the CHECK constraint is not only recognized but also enforced, providing a means for better data validation and integrity.
Q21
Multiple ChoiceIdentify the correct SQL statement to create a table with a CHECK constraint ensuring that a column's value is greater than 0.
SQL Code
CREATE TABLE products (
product_id INT PRIMARY KEY,
price DECIMAL(10, 2),
CHECK (price > 0)
);
The CHECK constraint ensures that the price column's value must be greater than 0, preventing the insertion of invalid data.
Q23
Multiple ChoiceDetermine the correct SQL statement to enforce a CHECK constraint on a column to ensure values fall within a specific range.
SQL Code
CREATE TABLE employees (
employee_id INT PRIMARY KEY,
age INT,
CHECK (age BETWEEN 18 AND 65)
);
The CHECK constraint on the age column ensures that all values must fall within the range of 18 to 65.
Q24
Multiple ChoiceWhich SQL statement correctly defines a CHECK constraint on multiple columns?
SQL Code
CREATE TABLE transactions (
transaction_id INT PRIMARY KEY,
amount DECIMAL(10, 2),
transaction_type VARCHAR(10),
CHECK (amount > 0 AND transaction_type IN ('Credit', 'Debit'))
);
The CHECK constraint on multiple columns ensures that the amount is positive and the transaction_type is either 'Credit' or 'Debit'.
Q26
Multiple ChoiceIdentify the correct SQL statement to enforce a CHECK constraint ensuring a date is in the future.
SQL Code
CREATE TABLE events (
event_id INT PRIMARY KEY,
event_date DATE,
CHECK (event_date > CURDATE())
);
The CHECK constraint ensures that the event_date must be greater than the current date, meaning it must be in the future.
Q27
Multiple ChoiceDetermine the correct SQL statement to enforce a CHECK constraint ensuring a column value starts with a specific prefix.
SQL Code
CREATE TABLE departments (
department_id INT PRIMARY KEY,
department_code VARCHAR(10),
CHECK (department_code LIKE 'HR%')
);
The CHECK constraint with the LIKE operator ensures that the department_code column value must start with the prefix 'HR'.
Q30
Multiple ChoiceIdentify the correct SQL statement to create a table with a CHECK constraint ensuring a numeric value is within a specified range and not NULL.
SQL Code
CREATE TABLE sales (
sale_id INT PRIMARY KEY,
discount_percentage DECIMAL(5, 2),
CHECK (discount_percentage BETWEEN 0 AND 50 AND discount_percentage IS NOT NULL)
);
The CHECK constraint ensures that the discount_percentage must be within the range of 0 to 50 and cannot be NULL.