PostgreSQL Database Quiz Questions

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

The UNIQUE constraint in PostgreSQL ensures that all values in a column are different.

Q2
True / False

You can have multiple UNIQUE constraints on a single table in PostgreSQL.

Q3
True / False

A UNIQUE constraint automatically creates an index in PostgreSQL.

Q4
True / False

You can apply the UNIQUE constraint to multiple columns at once in PostgreSQL.

Q5
True / False

The UNIQUE constraint in PostgreSQL can include NULL values.

Q6
True / False

If you drop a UNIQUE constraint in PostgreSQL, the associated index is also dropped automatically.

Q7
True / False

You can add a UNIQUE constraint to an existing column with duplicate values in PostgreSQL.

Q8
True / False

UNIQUE constraints can be deferred in PostgreSQL, meaning their enforcement can be delayed until the end of a transaction.

Q9
True / False

PostgreSQL supports the use of the UNIQUE constraint on arrays.

Q10
True / False

In PostgreSQL, the UNIQUE constraint can be used in conjunction with the PRIMARY KEY constraint on the same column.

Q11
Single Choice

Which of the following SQL statements correctly creates a table with a UNIQUE constraint on the email column?

Q12
Single Choice

What is the primary purpose of using a UNIQUE constraint in MySQL?

Q13
Single Choice

How can you add a UNIQUE constraint to an existing column in a MySQL table?

Q14
Single Choice

Consider the following SQL statement. What happens if you try to insert a duplicate value into the email column?

SQL Code
CREATE TABLE employees (
 id INT PRIMARY KEY,
 email VARCHAR(255) UNIQUE
);
Q15
Single Choice

Given the following SQL code, how many UNIQUE constraints are defined on the products table?

SQL Code
CREATE TABLE products (
 product_id INT PRIMARY KEY,
 product_name VARCHAR(255),
 sku VARCHAR(100) UNIQUE,
 product_code VARCHAR(100) UNIQUE
);
Q16
Single Choice

How can you drop a UNIQUE constraint from a column in a MySQL table?

Q17
Single Choice

What will be the result of the following SQL code if there are already duplicate values in the username column?

SQL Code
ALTER TABLE users ADD UNIQUE (username);
Q18
Single Choice

How can you define a UNIQUE constraint on multiple columns in a MySQL table?

Q19
Single Choice

In MySQL, what is the difference between a PRIMARY KEY and a UNIQUE constraint?

Q20
Single Choice

Consider the following SQL statements. Which of the following is true regarding the creation of a composite UNIQUE constraint?

SQL Code
CREATE TABLE orders (
 order_id INT PRIMARY KEY,
 customer_id INT,
 order_date DATE,
 UNIQUE (customer_id, order_date)
);
Q21
Multiple Choice

Which SQL command creates a table with a UNIQUE constraint on the 'email' column in PostgreSQL?

SQL Code
CREATE TABLE users (
 user_id SERIAL PRIMARY KEY,
 email VARCHAR(255) UNIQUE
);
Q22
Multiple Choice

Which SQL command creates a table with a UNIQUE constraint on multiple columns in PostgreSQL?

SQL Code
CREATE TABLE orders (
 order_id SERIAL PRIMARY KEY,
 customer_id INT NOT NULL,
 product_id INT NOT NULL,
 UNIQUE (customer_id, product_id)
);
Q23
Multiple Choice

Which SQL command adds a UNIQUE constraint to an existing column in PostgreSQL?

SQL Code
ALTER TABLE employees
ADD CONSTRAINT unique_email UNIQUE (email);
Q24
Multiple Choice

Which SQL command drops an existing UNIQUE constraint from a table in PostgreSQL?

SQL Code
ALTER TABLE users
DROP CONSTRAINT unique_email;
Q25
Multiple Choice

Which SQL command creates a table with a UNIQUE constraint that ignores NULL values in PostgreSQL?

SQL Code
CREATE TABLE contacts (
 contact_id SERIAL PRIMARY KEY,
 phone_number VARCHAR(20) UNIQUE
);
Q26
Multiple Choice

Which SQL command creates a table with a case-insensitive UNIQUE constraint in PostgreSQL?

SQL Code
CREATE TABLE products (
 product_id SERIAL PRIMARY KEY,
 product_code CITEXT UNIQUE
);
Q27
Multiple Choice

Which SQL command creates a table with a UNIQUE constraint on a computed column in PostgreSQL?

SQL Code
CREATE TABLE invoices (
 invoice_id SERIAL PRIMARY KEY,
 total_amount NUMERIC(10, 2),
 tax_amount NUMERIC(10, 2),
 UNIQUE (total_amount + tax_amount)
);
Q28
Multiple Choice

Which SQL command creates a table with a UNIQUE constraint that applies to a specific condition in PostgreSQL?

SQL Code
CREATE TABLE employees (
 employee_id SERIAL PRIMARY KEY,
 email VARCHAR(255),
 department VARCHAR(50),
 UNIQUE (email) WHERE department = 'Sales'
);
Q29
Multiple Choice

Which SQL command creates a table with a UNIQUE constraint that ensures a column's value is unique across multiple tables in PostgreSQL?

SQL Code
CREATE TABLE users (
 user_id SERIAL PRIMARY KEY,
 email VARCHAR(255) UNIQUE
);

CREATE TABLE admins (
 admin_id SERIAL PRIMARY KEY,
 email VARCHAR(255) UNIQUE
);

ALTER TABLE admins ADD CONSTRAINT unique_email_global EXCLUDE USING btree (email WITH =);
Q30
Multiple Choice

Which SQL command creates a table with a UNIQUE constraint and handles violations using a constraint name in PostgreSQL?

SQL Code
CREATE TABLE members (
 member_id SERIAL PRIMARY KEY,
 username VARCHAR(50) UNIQUE CONSTRAINT unique_username
);

INSERT INTO members (username) VALUES ('john_doe') ON CONFLICT ON CONSTRAINT unique_username DO NOTHING;