PostgreSQL Database Quiz Questions

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

In PostgreSQL, a column defined as NOT NULL cannot store NULL values.

Q2
True / False

The default setting for a column in PostgreSQL is NOT NULL.

Q3
True / False

In PostgreSQL, a column with a NOT NULL constraint can be altered to allow NULL values.

Q4
True / False

You can use the IS NULL condition in a PostgreSQL SELECT statement to filter rows with NULL values in a specific column.

Q5
True / False

In PostgreSQL, the COALESCE function can be used to return the first non-NULL value from a list of arguments.

Q6
True / False

In PostgreSQL, you cannot add a NOT NULL constraint to an existing column that contains NULL values

Q7
True / False

PostgreSQL treats empty strings as NULL values.

Q8
True / False

You can create a PostgreSQL table with a column that has both NULL and NOT NULL constraints.

Q9
True / False

In PostgreSQL, using the DISTINCT keyword will ignore NULL values in the result set.

Q10
True / False

: In PostgreSQL, when a NOT NULL constraint is added to an existing column using ALTER TABLE, the database performs a check to ensure there are no NULL values in that column before applying the constraint.

Q11
Single Choice

What will the following SQL query return if the info column contains JSON data and info->"$.name" is NULL?

SQL Code
SELECT JSON_NULL(info->"$.name") FROM users;
Q12
Single Choice

Which of the following is a valid check for a JSON field in MySQL that is NOT NULL?

Q13
Single Choice

Which MySQL function can be used to check if a JSON path expression returns NULL?

Q14
Single Choice

Given the following table orders with a JSON column order_details, how would you retrieve rows where the JSON field order_details->"$.status" is NULL?

SQL Code
SELECT * FROM orders WHERE _________;
Q15
Single Choice

In MySQL, what is the difference between JSON_NULL and IS NULL when querying JSON data?

Q16
Single Choice

How can you check if a specific key in a JSON column is NOT NULL in MySQL?

SQL Code
SELECT * FROM products WHERE _________;
Q17
Single Choice

What does the following SQL query return if the settings column contains JSON data and the value of settings->"$.enabled" is explicitly null?

SQL Code
SELECT settings->"$.enabled" IS NOT NULL FROM users;
Q18
Single Choice

How would you filter rows in a MySQL table where a JSON field metadata->"$.isActive" is NOT NULL and its value is TRUE?

SQL Code
SELECT * FROM users WHERE _________;
Q19
Single Choice

How can you handle a situation in MySQL where a JSON column may contain a NULL value that needs to be replaced with a default string "N/A"?

SQL Code
SELECT _________ FROM orders;
Q20
Single Choice

Consider a MySQL table configurations with a JSON column settings containing various configuration parameters. How would you write a query to select rows where the timeout parameter in the settings JSON field is NULL and also where the maxRetries parameter is NOT NULL?

SQL Code
SELECT * FROM configurations WHERE _________;
Q21
Multiple Choice

Which SQL command creates a table with a column that allows NULL values in PostgreSQL?

SQL Code
CREATE TABLE employees (
 employee_id SERIAL PRIMARY KEY,
 first_name VARCHAR(50),
 last_name VARCHAR(50) NULL
);
Q22
Multiple Choice

Which SQL command creates a table with a column that does not allow NULL values in PostgreSQL?

SQL Code
CREATE TABLE customers (
 customer_id SERIAL PRIMARY KEY,
 email VARCHAR(100) NOT NULL
);
Q23
Multiple Choice

Which SQL command is used to alter an existing column to disallow NULL values in PostgreSQL?

SQL Code
ALTER TABLE orders
ALTER COLUMN order_date SET NOT NULL;
Q24
Multiple Choice

Which SQL command is used to alter a column to allow NULL values in PostgreSQL?

SQL Code
ALTER TABLE products
ALTER COLUMN price DROP NOT NULL;
Q25
Multiple Choice

Which SQL command creates a table with both NULL and NOT NULL columns in PostgreSQL?

SQL Code
CREATE TABLE inventory (
 item_id SERIAL PRIMARY KEY,
 item_name VARCHAR(100) NOT NULL,
 item_description TEXT,
 quantity INT NOT NULL
);
Q26
Multiple Choice

Which SQL command creates a table with a default value that is NOT NULL in PostgreSQL?

SQL Code
CREATE TABLE users (
 user_id SERIAL PRIMARY KEY,
 username VARCHAR(50) NOT NULL,
 status VARCHAR(20) NOT NULL DEFAULT 'active'
);
Q27
Multiple Choice

Which SQL command would you use to enforce a NOT NULL constraint on an existing column with NULL values in PostgreSQL?

SQL Code
UPDATE employees
SET email = 'unknown@example.com'
WHERE email IS NULL;

ALTER TABLE employees
ALTER COLUMN email SET NOT NULL;
Q28
Multiple Choice

Which SQL command removes the NOT NULL constraint from a column that has a default value in PostgreSQL?

SQL Code
ALTER TABLE orders
ALTER COLUMN delivery_date DROP NOT NULL;
Q29
Multiple Choice

Which SQL command defines a column as NOT NULL but provides a default value in PostgreSQL?

SQL Code
CREATE TABLE accounts (
 account_id SERIAL PRIMARY KEY,
 balance NUMERIC(10, 2) NOT NULL DEFAULT 0.00
);
Q30
Multiple Choice

Which SQL command creates a table with a combination of NULL, NOT NULL, and DEFAULT constraints in PostgreSQL?

SQL Code
CREATE TABLE employees (
 employee_id SERIAL PRIMARY KEY,
 first_name VARCHAR(50) NOT NULL,
 last_name VARCHAR(50),
 hire_date DATE NOT NULL DEFAULT CURRENT_DATE
);