PostgreSQL Database Quiz Questions

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

In PostgreSQL, the CREATE TABLE command is used to create a new table in the current database.

Q2
True / False

PostgreSQL does not allow specifying a default value for a column when creating a table.

Q3
True / False

The SERIAL keyword in PostgreSQL is used to create an auto-incrementing integer column.

Q4
True / False

In PostgreSQL, you cannot create a table without specifying a primary key.

Q5
True / False

PostgreSQL allows the use of foreign key constraints when creating a table.

Q6
True / False

The CREATE TABLE command in PostgreSQL does not support the CHECK constraint.

Q7
True / False

In PostgreSQL, the INHERITS keyword allows a table to inherit columns from one or more parent tables

Q8
True / False

PostgreSQL supports partitioning tables using the PARTITION BY clause in the CREATE TABLE statement.

Q9
True / False

The CREATE TABLE AS command in PostgreSQL creates a new table and populates it with the result of a query.

Q10
True / False

In PostgreSQL, you can use the CREATE TABLE command to create a table with an index on a column by specifying the index directly within the CREATE TABLE statement.

Q11
Single Choice

Which of the following is the correct syntax to create a table named employees with columns id (integer) and name (varchar)?

Q12
Single Choice

What is the default storage engine in MySQL 8.0 when creating a table without specifying the engine?

Q13
Single Choice

Which MySQL statement is used to create a table named customers with a primary key on the customer_id column?

Q14
Single Choice

What does the following MySQL statement do?

SQL Code
CREATE TABLE orders (
 order_id INT AUTO_INCREMENT,
 order_date DATE,
 PRIMARY KEY (order_id)
);
Q15
Single Choice

How would you define a foreign key in the following MySQL CREATE TABLE statement?

SQL Code
CREATE TABLE orders (
 order_id INT PRIMARY KEY,
 customer_id INT,
 CONSTRAINT fk_customer FOREIGN KEY (customer_id) REFERENCES customers(customer_id)
);
Q16
Single Choice

In MySQL, which of the following correctly adds a unique constraint while creating a table?

Q17
Single Choice

Consider the following CREATE TABLE statement in MySQL:

SQL Code
CREATE TABLE inventory (
 item_id INT,
 item_name VARCHAR(50),
 item_quantity INT CHECK (item_quantity >= 0)
);
What does the CHECK constraint do in this context?
Q18
Single Choice

Which of the following CREATE TABLE statements defines a composite primary key?

Q19
Single Choice

How does MySQL handle a table creation if a table with the same name already exists, and the CREATE TABLE statement does not include IF NOT EXISTS?

Q20
Single Choice

What happens when you run the following MySQL CREATE TABLE statement if the database is set to strict SQL mode?

SQL Code
CREATE TABLE transactions (
 transaction_id INT NOT NULL,
 transaction_date DATE,
 amount DECIMAL(10,2) DEFAULT 'abc',
 PRIMARY KEY (transaction_id)
);
Q21
Multiple Choice

Which SQL command correctly creates a basic table in PostgreSQL with a primary key?

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

Which SQL command is used to create a table with a foreign key constraint in PostgreSQL?

SQL Code
CREATE TABLE orders (
 order_id SERIAL PRIMARY KEY,
 customer_id INT REFERENCES customers(customer_id),
 order_date DATE NOT NULL
);
Q23
Multiple Choice

Which SQL command creates a table with a composite primary key in PostgreSQL?

SQL Code
CREATE TABLE order_items (
 order_id INT,
 product_id INT,
 quantity INT NOT NULL,
 PRIMARY KEY (order_id, product_id)
);
Q24
Multiple Choice

Which SQL command correctly creates a table with a UNIQUE constraint on one of its columns?

SQL Code
CREATE TABLE users (
 user_id SERIAL PRIMARY KEY,
 username VARCHAR(50) UNIQUE NOT NULL,
 password VARCHAR(100) NOT NULL
);
Q25
Multiple Choice

Which SQL command creates a table in PostgreSQL with a CHECK constraint to ensure a column's value is within a specific range?

SQL Code
CREATE TABLE products (
 product_id SERIAL PRIMARY KEY,
 product_name VARCHAR(100) NOT NULL,
 price NUMERIC(10, 2) CHECK (price > 0 AND price < 10000)
);
Q26
Multiple Choice

Which SQL command creates a table with a column that has a default value in PostgreSQL?

SQL Code
CREATE TABLE accounts (
 account_id SERIAL PRIMARY KEY,
 username VARCHAR(50) NOT NULL,
 created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
Q27
Multiple Choice

Which SQL command is used to create a table that automatically deletes rows older than a certain age in PostgreSQL?

SQL Code
CREATE TABLE session_logs (
 session_id SERIAL PRIMARY KEY,
 user_id INT NOT NULL,
 login_time TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP,
 CONSTRAINT chk_login_time CHECK (login_time > CURRENT_TIMESTAMP - INTERVAL '1 year')
);
Q28
Multiple Choice

Which SQL command creates a partitioned table in PostgreSQL by range?

SQL Code
CREATE TABLE sales (
 sale_id SERIAL PRIMARY KEY,
 sale_date DATE NOT NULL,
 amount NUMERIC(10, 2) NOT NULL
) PARTITION BY RANGE (sale_date);
Q29
Multiple Choice

Which SQL command is used to create a table with a JSONB column in PostgreSQL?

SQL Code
CREATE TABLE events (
 event_id SERIAL PRIMARY KEY,
 event_data JSONB NOT NULL,
 event_time TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP
);
Q30
Multiple Choice

Which SQL command creates a table with a generated column in PostgreSQL?

SQL Code
CREATE TABLE invoices (
 invoice_id SERIAL PRIMARY KEY,
 amount NUMERIC(10, 2) NOT NULL,
 tax NUMERIC(10, 2) GENERATED ALWAYS AS (amount * 0.15) STORED
);