MySQL Database Quiz Questions

Course Name:MySQL
Chapter Name:Chapter 5 - DDL (Data Definition Language)
Lesson Content Link:CHECK Constraint
Current Quiz Count:30
Progress
0%
Q1
True / False

MySQL enforces the CHECK constraint in the same way it enforces the NOT NULL constraint.

Q2
True / False

You can use the CHECK constraint in a MySQL CREATE TABLE statement.

Q3
True / False

The CHECK constraint in MySQL is used to limit the values that can be placed in a column.

Q4
True / False

MySQL fully supports and enforces the CHECK constraint starting from version 5.7.

Q5
True / False

In MySQL, the CHECK constraint can reference multiple columns in the same table.

Q6
True / False

In MySQL, you can add a CHECK constraint to an existing table using the ALTER TABLE statement.

Q7
True / False

In MySQL, you can create a CHECK constraint that uses subqueries.

Q8
True / False

The CHECK constraint in MySQL can be used to enforce domain integrity by ensuring that only valid domain values are entered into a column.

Q9
True / False

In MySQL, a CHECK constraint can reference another table to ensure referential integrity.

Q10
True / False

As of MySQL 8.0.16, the CHECK constraint is both recognized and enforced, allowing for more robust data validation within the database.

Q11
Single Choice

What is the primary purpose of the CHECK constraint in MySQL?

Q12
Single Choice

Can the CHECK constraint be applied to multiple columns in a MySQL table?

Q13
Single Choice

Which of the following is a correct way to define a CHECK constraint in MySQL?

Q14
Single Choice

In MySQL, where can a CHECK constraint be defined?

Q15
Single Choice

What happens if a value violates a CHECK constraint in MySQL?

Q16
Single Choice

Can you use functions within a CHECK constraint in MySQL?

Q17
Single Choice

How can a CHECK constraint be removed from a column in MySQL?

Q18
Single Choice

Is it possible to disable a CHECK constraint in MySQL temporarily?

Q19
Single Choice

Which of the following is true about the CHECK constraint in MySQL 8.0 and later?

Q20
Single Choice

In MySQL, which statement correctly adds a CHECK constraint to ensure that the salary column in the employees table is always greater than 0?

Q21
Multiple Choice

Identify 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)
);
Q22
Multiple Choice

Choose the correct SQL statement to add a CHECK constraint to an existing table ensuring a column's value is non-negative.

SQL Code
ALTER TABLE orders
ADD CHECK (quantity >= 0);
Q23
Multiple Choice

Determine 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)
);
Q24
Multiple Choice

Which 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'))
);
Q25
Multiple Choice

Select the correct SQL statement to drop an existing CHECK constraint from a table.

SQL Code
ALTER TABLE employees
DROP CONSTRAINT chk_age;
Q26
Multiple Choice

Identify 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())
);
Q27
Multiple Choice

Determine 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%')
);
Q28
Multiple Choice

Which SQL statement correctly adds a CHECK constraint to ensure an integer column has only even values?

SQL Code
ALTER TABLE inventory
ADD CONSTRAINT chk_even
CHECK (stock_quantity % 2 = 0);
Q29
Multiple Choice

Select the correct SQL statement to add a CHECK constraint to ensure a string column is not empty.

SQL Code
ALTER TABLE users
ADD CHECK (username <> '');
Q30
Multiple Choice

Identify 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)
);