PostgreSQL Database Quiz Questions

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

In PostgreSQL, a CHECK constraint can only be applied to a single column.

Q2
True / False

The CHECK constraint in PostgreSQL is enforced by the database whenever an insert or update operation is performed.

Q3
True / False

In PostgreSQL, CHECK constraints can reference other tables.

Q4
True / False

In PostgreSQL, a CHECK constraint can use expressions involving multiple columns of the same table.

Q5
True / False

In PostgreSQL, CHECK constraints can be temporarily disabled and later re-enabled.

Q6
True / False

In PostgreSQL, CHECK constraints are validated for existing data in the table when they are first created.

Q7
True / False

PostgreSQL allows the creation of a CHECK constraint using custom functions.

Q8
True / False

CHECK constraints in PostgreSQL can be used to enforce referential integrity.

Q9
True / False

In PostgreSQL, CHECK constraints can be defined at the table level, affecting multiple columns.

Q10
True / False

In PostgreSQL, the CHECK constraint condition can include subqueries.

Q11
Single Choice

Which SQL statement correctly adds a CHECK constraint to ensure that the "age" column in a MySQL table only allows values greater than 18?

SQL Code
ALTER TABLE employees
ADD CONSTRAINT chk_age CHECK (age > 18);
Q12
Single Choice

In MySQL, what does the following CHECK constraint do?

SQL Code
CHECK (salary >= 0)
Q13
Single Choice

Does MySQL enforce CHECK constraints by default?

Q14
Single Choice

Given the following table creation SQL code, what will happen if you try to insert a row with a status value of 'Archived'?

SQL Code
CREATE TABLE orders (
 order_id INT PRIMARY KEY,
 status ENUM('Pending', 'Shipped', 'Delivered') CHECK (status IN ('Pending', 'Shipped', 'Delivered'))
);
Q15
Single Choice

What is the correct way to define a CHECK constraint to ensure the quantity column in the products table is always greater than zero?

SQL Code
CREATE TABLE products (
 product_id INT PRIMARY KEY,
 product_name VARCHAR(255),
 quantity INT CHECK (quantity > 0)
);
Q16
Single Choice

When creating a table in MySQL, which of the following statements about the CHECK constraint is true?

Q17
Single Choice

You have the following MySQL table definition. Which of the following statements about inserting records is correct?

SQL Code
CREATE TABLE employees (
 emp_id INT PRIMARY KEY,
 salary DECIMAL(10,2),
 CHECK (salary > 3000 AND salary < 10000)
);
Q18
Single Choice

Which SQL statement would add a CHECK constraint to an existing MySQL table to ensure that the price column is always greater than zero?

SQL Code
ALTER TABLE products
ADD CONSTRAINT chk_price CHECK (price > 0);
Q19
Single Choice

How would you define a CHECK constraint in MySQL to ensure the birth_date column in the users table does not allow future dates?

SQL Code
CREATE TABLE users (
 user_id INT PRIMARY KEY,
 birth_date DATE,
 CHECK (birth_date <= CURRENT_DATE)
);
Q20
Single Choice

Which of the following accurately describes the current status of CHECK constraints in MySQL 8.0?

Q21
Multiple Choice

Which SQL command creates a table with a CHECK constraint ensuring that the 'age' column only accepts values greater than or equal to 18?

SQL Code
CREATE TABLE users (
 user_id SERIAL PRIMARY KEY,
 age INT,
 CHECK (age >= 18)
);
Q22
Multiple Choice

Which SQL command creates a table with a CHECK constraint ensuring that the 'salary' column is between 30000 and 200000?

SQL Code
CREATE TABLE employees (
 employee_id SERIAL PRIMARY KEY,
 salary NUMERIC(10, 2) NOT NULL,
 CHECK (salary BETWEEN 30000 AND 200000)
);
Q23
Multiple Choice

Which SQL command adds a CHECK constraint to ensure that the 'stock' column in the 'products' table is always non-negative?

SQL Code
ALTER TABLE products
ADD CONSTRAINT check_stock CHECK (stock >= 0);
Q24
Multiple Choice

Which SQL command creates a table with a CHECK constraint on multiple columns to ensure that the 'start_date' is earlier than the 'end_date'?

SQL Code
CREATE TABLE events (
 event_id SERIAL PRIMARY KEY,
 start_date DATE NOT NULL,
 end_date DATE NOT NULL,
 CHECK (start_date < end_date)
);
Q25
Multiple Choice

Which SQL command creates a table with a CHECK constraint that ensures 'discount' is less than 'price' in the 'products' table?

SQL Code
CREATE TABLE products (
 product_id SERIAL PRIMARY KEY,
 price NUMERIC(10, 2) NOT NULL,
 discount NUMERIC(10, 2),
 CHECK (discount < price)
);
Q26
Multiple Choice

Which SQL command alters an existing table to add a CHECK constraint ensuring that 'quantity' is positive in PostgreSQL?

SQL Code
ALTER TABLE inventory
ADD CONSTRAINT check_quantity_positive CHECK (quantity > 0);
Q27
Multiple Choice

Which SQL command adds a CHECK constraint to ensure that a 'percentage' column is between 0 and 100 in PostgreSQL?

SQL Code
ALTER TABLE assessments
ADD CONSTRAINT check_percentage_range CHECK (percentage >= 0 AND percentage <= 100);
Q28
Multiple Choice

Which SQL command creates a table with a CHECK constraint that ensures the 'rating' column only accepts values from 1 to 5 in PostgreSQL?

SQL Code
CREATE TABLE reviews (
 review_id SERIAL PRIMARY KEY,
 rating INT NOT NULL,
 CHECK (rating BETWEEN 1 AND 5)
);
Q29
Multiple Choice

Which SQL command creates a table with a CHECK constraint that ensures a 'code' column starts with 'ABC' in PostgreSQL?

SQL Code
CREATE TABLE items (
 item_id SERIAL PRIMARY KEY,
 code VARCHAR(10) NOT NULL,
 CHECK (code LIKE 'ABC%')
);
Q30
Multiple Choice

Which SQL command creates a table with a CHECK constraint that ensures the 'age' column is greater than 0 and less than 120 in PostgreSQL?

SQL Code
CREATE TABLE persons (
 person_id SERIAL PRIMARY KEY,
 age INT NOT NULL,
 CHECK (age > 0 AND age < 120)
);