PostgreSQL Database Quiz Questions

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

In PostgreSQL, the SERIAL keyword is used to create an auto-incrementing integer column.

Q2
True / False

PostgreSQL does not support auto-incrementing columns.

Q3
True / False

The SERIAL keyword automatically creates a sequence in PostgreSQL.

Q4
True / False

You can create an auto-incrementing column in PostgreSQL without using the SERIAL keyword.

Q5
True / False

The BIGSERIAL keyword in PostgreSQL is used to create a 64-bit auto-incrementing integer column.

Q6
True / False

Using SERIAL in PostgreSQL guarantees that the sequence values will always be continuous without gaps.

Q7
True / False

In PostgreSQL, you can alter an existing column to make it an auto-incrementing column using the SERIAL keyword.

Q8
True / False

In PostgreSQL, the SERIAL data type can be used in a composite primary key.

Q9
True / False

In PostgreSQL, you can reset a sequence used for auto-incrementing columns using the ALTER SEQUENCE command.

Q10
True / False

When migrating from MySQL to PostgreSQL, you can directly map MySQL's AUTO_INCREMENT to PostgreSQL's SERIAL without any issues.

Q11
Single Choice

AUTO_INCREMENT attribute in MySQL?

Q12
Single Choice

In MySQL, which data types can be used with AUTO_INCREMENT?

Q13
Single Choice

Which MySQL statement correctly creates a table with an AUTO_INCREMENT column

SQL Code
CREATE TABLE users (
 user_id VARCHAR(10) AUTO_INCREMENT PRIMARY KEY,
 username VARCHAR(50)
);
Q14
Single Choice

How can you set the initial value of an AUTO_INCREMENT column in MySQL?

SQL Code
ALTER TABLE table_name AUTO_INCREMENT = 100;
Q15
Single Choice

If you insert a new row without specifying a value for order_id, what value will order_id have?

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

What will happen if you try to insert a value for an AUTO_INCREMENT column in MySQL?

SQL Code
INSERT INTO users (user_id, username) VALUES (5, 'JohnDoe');
Q17
Single Choice

What is the purpose of the LAST_INSERT_ID() function in MySQL?

Q18
Single Choice

In a MySQL table with an AUTO_INCREMENT column, what will happen if you delete the row with the highest AUTO_INCREMENT value and then insert a new row?

Q19
Single Choice

What problem can arise from using AUTO_INCREMENT in this self-referencing table?

SQL Code
CREATE TABLE employees (
 emp_id INT AUTO_INCREMENT PRIMARY KEY,
 name VARCHAR(50),
 manager_id INT,
 FOREIGN KEY (manager_id) REFERENCES employees(emp_id)
);
Q20
Single Choice

In MySQL 8.0, how can you configure an AUTO_INCREMENT column to increment by a value other than 1?

Q21
Multiple Choice

Which SQL command creates a table with an AUTO INCREMENT column in PostgreSQL using the SERIAL data type?

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

Which SQL command defines an AUTO INCREMENT column using the IDENTITY keyword in PostgreSQL?

SQL Code
CREATE TABLE orders (
 order_id INTEGER GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
 order_date DATE NOT NULL,
 customer_id INT
);
Q23
Multiple Choice

Which SQL command adds an AUTO INCREMENT column to an existing table in PostgreSQL?

SQL Code
ALTER TABLE customers
ADD COLUMN customer_id SERIAL PRIMARY KEY;
Q24
Multiple Choice

Which SQL command creates a table with a BIGINT AUTO INCREMENT column using the BIGSERIAL data type in PostgreSQL?

SQL Code
CREATE TABLE transactions (
 transaction_id BIGSERIAL PRIMARY KEY,
 amount NUMERIC(10, 2),
 transaction_date TIMESTAMPTZ NOT NULL
);
Q25
Multiple Choice

Which SQL command uses the GENERATED BY DEFAULT AS IDENTITY option to define an AUTO INCREMENT column in PostgreSQL?

SQL Code
CREATE TABLE invoices (
 invoice_id INTEGER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
 invoice_date DATE NOT NULL,
 total NUMERIC(10, 2)
);
Q26
Multiple Choice

Which SQL command resets the sequence of an AUTO INCREMENT column in PostgreSQL?

SQL Code
ALTER SEQUENCE employees_employee_id_seq RESTART WITH 1;
Q27
Multiple Choice

Which SQL command creates a table with a custom start value for an AUTO INCREMENT column using the IDENTITY keyword in PostgreSQL?

SQL Code
CREATE TABLE tickets (
 ticket_id INTEGER GENERATED BY DEFAULT AS IDENTITY (START WITH 1000) PRIMARY KEY,
 issue_description TEXT NOT NULL
);
Q28
Multiple Choice

Which SQL command removes the AUTO INCREMENT property from a column in PostgreSQL?

SQL Code
ALTER TABLE employees
ALTER COLUMN employee_id DROP IDENTITY;
Q29
Multiple Choice

Which SQL command modifies the increment value of an existing AUTO INCREMENT column in PostgreSQL?

SQL Code
ALTER SEQUENCE employees_employee_id_seq INCREMENT BY 10;
Q30
Multiple Choice

Which SQL command creates a table with a BIGINT AUTO INCREMENT column starting from a custom value in PostgreSQL?

SQL Code
CREATE TABLE logs (
 log_id BIGINT GENERATED ALWAYS AS IDENTITY (START WITH 1000000) PRIMARY KEY,
 log_message TEXT NOT NULL,
 log_timestamp TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP
);