PostgreSQL Database Quiz Questions

Course Name:PostgreSQL
Chapter Name:Chapter 6 - DML (Data Manipulation Language)
Lesson Content Link:INSERT
Current Quiz Count:30
Progress
0%
Q1
True / False

In PostgreSQL, the INSERT statement is used to add new rows to an existing table.

Q2
True / False

The syntax INSERT INTO table_name VALUES (value1, value2, ...); is used to insert a new row in PostgreSQL.

Q3
True / False

You can insert multiple rows into a PostgreSQL table with a single INSERT INTO statement.

Q4
True / False

In PostgreSQL, you must always specify the column names when using the INSERT INTO statement.

Q5
True / False

The RETURNING clause in PostgreSQL can be used with INSERT INTO to return the values of specified columns after the insertion.

Q6
True / False

The ON CONFLICT clause in PostgreSQL allows you to handle conflicts that arise when inserting data.

Q7
True / False

In PostgreSQL, the INSERT INTO ... SELECT statement can be used to insert data into a table based on a query.

Q8
True / False

You cannot use a CTE (Common Table Expression) with an INSERT statement in PostgreSQL.

Q9
True / False

The INSERT command in PostgreSQL supports the WITH clause for executing multiple INSERT operations in a single statement.

Q10
True / False

In PostgreSQL, the INSERT statement does not support conditional inserts using the WHERE clause.

Q11
Single Choice

Which of the following is the correct syntax to insert a new row into a table named employees with columns id, name, and salary in PostgreSQL?

Q12
Single Choice

What will happen if you omit a column in the INSERT statement in PostgreSQL that does not have a default value or allows NULLs?

Q13
Single Choice

How do you insert multiple rows into a PostgreSQL table using a single INSERT statement?

Q14
Single Choice

What is the correct way to insert data into a table and return the inserted rows in PostgreSQL?

Q15
Single Choice

Which of the following SQL commands will insert a row into the departments table only if the row does not already exist, based on the department_id in PostgreSQL?

Q16
Single Choice

How can you insert data into a table using a SELECT statement in PostgreSQL?

Q17
Single Choice

When using the INSERT INTO ... SELECT statement, which clause can be used to handle conflicts that arise due to duplicate keys in PostgreSQL?

Q18
Single Choice

Consider a table products with a unique constraint on the product_code column. Which PostgreSQL statement will insert a new row, or update the existing row if the product_code already exists?

Q19
Single Choice

How can you insert a row into the orders table, ensuring that the order_id is automatically generated, but also include a custom value for it using PostgreSQL's INSERT command?

Q20
Single Choice

In PostgreSQL, which of the following is the correct approach to insert data from one table into another and handle potential conflicts by ignoring the conflict but returning the rows that were successfully inserted?

Q21
Multiple Choice

Which SQL command inserts a new row into the 'employees' table with all column values provided?

SQL Code
INSERT INTO employees (employee_id, first_name, last_name, department_id)
VALUES (1, 'John', 'Doe', 101);
Q22
Multiple Choice

Which SQL command inserts a new row with only some column values provided, using DEFAULT for others?

SQL Code
INSERT INTO orders (order_id, order_date, customer_id)
VALUES (1, CURRENT_DATE, DEFAULT);
Q23
Multiple Choice

Which SQL command inserts multiple rows into the 'products' table in a single query?

SQL Code
INSERT INTO products (product_id, product_name, price)
VALUES (1, 'Laptop', 999.99),
 (2, 'Tablet', 499.99);
Q24
Multiple Choice

Which SQL command uses the RETURNING clause to get the inserted row's primary key value?

SQL Code
INSERT INTO customers (first_name, last_name)
VALUES ('Jane', 'Doe')
RETURNING customer_id;
Q25
Multiple Choice

Which SQL command uses the ON CONFLICT clause to handle duplicate keys by doing nothing?

SQL Code
INSERT INTO users (user_id, username)
VALUES (1, 'jdoe')
ON CONFLICT (user_id) DO NOTHING;
Q26
Multiple Choice

Which SQL command inserts a new row into a table with a JSONB column and assigns default values to missing fields?

SQL Code
INSERT INTO settings (config_id, config_data)
VALUES (1, '{"theme": "dark"}')
ON CONFLICT (config_id)
DO UPDATE SET config_data = jsonb_set(settings.config_data, '{theme}', '"dark"', true);
Q27
Multiple Choice

Which SQL command inserts a row and returns the inserted row's entire data?

SQL Code
INSERT INTO employees (first_name, last_name, department_id)
VALUES ('Alice', 'Smith', 101)
RETURNING *;
Q28
Multiple Choice

Which SQL command performs an INSERT with a subquery that selects data from another table?

SQL Code
INSERT INTO sales (product_id, sale_date, quantity)
SELECT product_id, CURRENT_DATE, 1 FROM products WHERE product_name = 'Laptop';
Q29
Multiple Choice

Which SQL command uses the INSERT...ON CONFLICT clause to handle duplicate keys by updating the conflicting row?

SQL Code
INSERT INTO inventory (product_id, stock)
VALUES (1, 100)
ON CONFLICT (product_id)
DO UPDATE SET stock = EXCLUDED.stock + inventory.stock;
Q30
Multiple Choice

Which SQL command performs an INSERT with data returned from a CTE (Common Table Expression) in PostgreSQL?

SQL Code
WITH new_products AS (
 SELECT product_id, product_name FROM products WHERE product_id > 100
)
INSERT INTO sales (product_id, sale_date)
SELECT product_id, CURRENT_DATE FROM new_products;