Q1
True / FalseIn PostgreSQL, a CHECK constraint can only be applied to a single column.
A CHECK constraint can be applied to a single column or multiple columns. It is a condition that must be true for all rows in the table.
Q2
True / FalseThe CHECK constraint in PostgreSQL is enforced by the database whenever an insert or update operation is performed.
PostgreSQL enforces CHECK constraints during both insert and update operations to ensure data integrity.
Q3
True / FalseIn PostgreSQL, CHECK constraints can reference other tables.
CHECK constraints cannot reference columns in other tables. They are limited to conditions within the same table.
Q4
True / FalseIn PostgreSQL, a CHECK constraint can use expressions involving multiple columns of the same table.
CHECK constraints can use expressions that involve multiple columns of the same table to enforce complex conditions.
Q5
True / FalseIn PostgreSQL, CHECK constraints can be temporarily disabled and later re-enabled.
CHECK constraints can be disabled using ALTER TABLE ... ALTER CONSTRAINT ... NO VALIDATE and re-enabled with ALTER TABLE ... VALIDATE CONSTRAINT ....
Q6
True / FalseIn PostgreSQL, CHECK constraints are validated for existing data in the table when they are first created.
When a CHECK constraint is created, PostgreSQL validates it against existing data to ensure all rows satisfy the condition.
Q7
True / FalsePostgreSQL allows the creation of a CHECK constraint using custom functions.
PostgreSQL allows the use of custom functions within CHECK constraints to enforce more complex rules
Q8
True / FalseCHECK constraints in PostgreSQL can be used to enforce referential integrity.
CHECK constraints cannot enforce referential integrity, which is the job of foreign keys. CHECK constraints enforce conditions on the data within the same table.
Q9
True / FalseIn PostgreSQL, CHECK constraints can be defined at the table level, affecting multiple columns.
CHECK constraints can be defined at the table level and can include conditions that involve multiple columns within the table.
Q10
True / FalseIn PostgreSQL, the CHECK constraint condition can include subqueries.
CHECK constraints cannot include subqueries. The condition must be a simple expression that does not involve subqueries or references to other tables.
Q22
Multiple ChoiceWhich 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)
);
This command ensures that the 'salary' column in the 'employees' table only accepts values between 30000 and 200000.
Q24
Multiple ChoiceWhich 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)
);
This command creates an 'events' table with a CHECK constraint that enforces the rule that 'start_date' must be earlier than 'end_date'.
Q25
Multiple ChoiceWhich 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)
);
This command creates a 'products' table with a CHECK constraint to ensure that 'discount' is always less than 'price'.