PostgreSQL Database Quiz Questions

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

The DEFAULT constraint in PostgreSQL is used to provide a default value for a column if no value is specified.

Q2
True / False

In PostgreSQL, a column with a DEFAULT constraint must always have a value specified during the insertion of a new row.

Q3
True / False

You can add a DEFAULT constraint to an existing column in a PostgreSQL table.

Q4
True / False

In PostgreSQL, the DEFAULT constraint can reference other columns in the same table.

Q5
True / False

Changing the default value of a column in PostgreSQL using the DEFAULT constraint will automatically update the existing rows with the new default value.

Q6
True / False

In PostgreSQL, the DEFAULT constraint can be used with all data types.

Q7
True / False

You can set a DEFAULT constraint to use a PostgreSQL function, such as NOW() for a timestamp column.

Q8
True / False

In PostgreSQL, removing a DEFAULT constraint from a column will remove all the existing default values from that column.

Q9
True / False

In PostgreSQL, the DEFAULT constraint can include arithmetic expressions, such as setting the default value of a column to 100 + 50.

Q10
True / False

When a DEFAULT constraint is specified for a column in PostgreSQL, it ensures that all values inserted into the column adhere to the specified default value.

Q11
Single Choice

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

Q12
Single Choice

Which of the following SQL statements correctly uses the DEFAULT constraint when creating a table?

Q13
Single Choice

If a column with a DEFAULT constraint is not included in an INSERT statement, what value will be assigned to that column?

Q14
Single Choice

What will be the value of the price column when the following INSERT statement is executed? INSERT INTO products (id, name) VALUES (1, 'Product A');

SQL Code
CREATE TABLE products (
 id INT PRIMARY KEY,
 name VARCHAR(100),
 price DECIMAL(10, 2) DEFAULT 19.99
);
Q15
Single Choice

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

Q16
Single Choice

Which of the following SQL statements removes the DEFAULT constraint from a column in MySQL?

Q17
Single Choice

Consider the following MySQL table definition:If an INSERT statement is executed without providing values for both order_date and status, what will be the default values for these columns?

SQL Code
CREATE TABLE orders (
 id INT PRIMARY KEY,
 order_date DATE DEFAULT CURRENT_DATE,
 status VARCHAR(20) DEFAULT 'pending'
);
Q18
Single Choice

What happens when you try to insert a NULL value into a column with both a DEFAULT constraint and a NOT NULL constraint?

SQL Code
CREATE TABLE employees (
 id INT PRIMARY KEY,
 name VARCHAR(50) NOT NULL DEFAULT 'John Doe',
 age INT NOT NULL DEFAULT 30
);

INSERT INTO employees (id, name, age) VALUES (1, NULL, 25);
Q19
Single Choice

Consider the following MySQL table and INSERT statement:

SQL Code
CREATE TABLE customers (
 id INT PRIMARY KEY,
 first_name VARCHAR(50) DEFAULT 'Guest',
 last_name VARCHAR(50) DEFAULT 'User'
);

INSERT INTO customers (id, first_name, last_name) VALUES (1, DEFAULT, 'Smith');
Q20
Single Choice

Given the following MySQL table:

SQL Code
CREATE TABLE inventory (
 product_id INT PRIMARY KEY,
 quantity INT DEFAULT 100,
 last_updated TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);
Q21
Multiple Choice

Which SQL command creates a table with a DEFAULT constraint on the 'status' column in PostgreSQL?

SQL Code
CREATE TABLE orders (
 order_id SERIAL PRIMARY KEY,
 status VARCHAR(20) NOT NULL DEFAULT 'pending'
);
Q22
Multiple Choice

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

SQL Code
ALTER TABLE users
ALTER COLUMN signup_date SET DEFAULT CURRENT_DATE;
Q23
Multiple Choice

Which SQL command creates a table with a DEFAULT constraint that uses an expression in PostgreSQL?

SQL Code
CREATE TABLE accounts (
 account_id SERIAL PRIMARY KEY,
 balance NUMERIC(12, 2) DEFAULT 1000 * 0.05
);
Q24
Multiple Choice

Which SQL command removes an existing DEFAULT constraint from a column in PostgreSQL?

SQL Code
ALTER TABLE employees
ALTER COLUMN job_title DROP DEFAULT;
Q25
Multiple Choice

Which SQL command creates a table with multiple columns having DEFAULT constraints in PostgreSQL?

SQL Code
CREATE TABLE products (
 product_id SERIAL PRIMARY KEY,
 price NUMERIC(10, 2) DEFAULT 9.99,
 stock INT DEFAULT 0
);
Q26
Multiple Choice

Which SQL command modifies an existing column to change its DEFAULT value in PostgreSQL?

SQL Code
ALTER TABLE employees
ALTER COLUMN salary SET DEFAULT 50000;
Q27
Multiple Choice

Which SQL command ensures that a DEFAULT constraint on a column uses a function as the default value in PostgreSQL?

SQL Code
CREATE TABLE logs (
 log_id SERIAL PRIMARY KEY,
 created_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP
);
Q28
Multiple Choice

Which SQL command creates a table with a DEFAULT constraint on a JSONB column in PostgreSQL?

SQL Code
CREATE TABLE configurations (
 config_id SERIAL PRIMARY KEY,
 settings JSONB DEFAULT '{}'
);
Q29
Multiple Choice

Which SQL command defines a DEFAULT constraint on a BOOLEAN column in PostgreSQL?

SQL Code
CREATE TABLE features (
 feature_id SERIAL PRIMARY KEY,
 is_enabled BOOLEAN DEFAULT TRUE
);
Q30
Multiple Choice

Which SQL command defines a DEFAULT constraint on a column with a UUID data type in PostgreSQL?

SQL Code
CREATE TABLE devices (
 device_id UUID DEFAULT gen_random_uuid() PRIMARY KEY,
 device_name VARCHAR(100) NOT NULL
);