Q1
True / FalseIn PostgreSQL, the SERIAL keyword is used to create an auto-incrementing integer column.
The SERIAL keyword in PostgreSQL creates an integer column that automatically increments by 1 for each new row inserted.
Q2
True / FalsePostgreSQL does not support auto-incrementing columns.
PostgreSQL supports auto-incrementing columns using the SERIAL keyword and sequences.
Q3
True / FalseThe SERIAL keyword automatically creates a sequence in PostgreSQL.
When using the SERIAL keyword, PostgreSQL automatically creates a sequence to handle the auto-incrementing values.
Q4
True / FalseYou can create an auto-incrementing column in PostgreSQL without using the SERIAL keyword.
You can create an auto-incrementing column using a custom sequence and the DEFAULT keyword with the nextval() function.
Q5
True / FalseThe BIGSERIAL keyword in PostgreSQL is used to create a 64-bit auto-incrementing integer column.
The BIGSERIAL keyword creates a column that auto-increments using a 64-bit integer, which is suitable for tables with a large number of rows.
Q6
True / FalseUsing SERIAL in PostgreSQL guarantees that the sequence values will always be continuous without gaps.
Sequences in PostgreSQL can have gaps, especially if transactions are rolled back, as the sequence values generated are not reused.
Q7
True / FalseIn PostgreSQL, you can alter an existing column to make it an auto-incrementing column using the SERIAL keyword.
The SERIAL keyword cannot be used with the ALTER TABLE command. Instead, you would need to create a sequence and set the column's default value using nextval().
Q8
True / FalseIn PostgreSQL, the SERIAL data type can be used in a composite primary key.
You can use the SERIAL data type in a composite primary key, but you need to define the sequence and default value explicitly as part of the composite key definition.
Q9
True / FalseIn PostgreSQL, you can reset a sequence used for auto-incrementing columns using the ALTER SEQUENCE command.
The ALTER SEQUENCE command can be used to restart a sequence at a specified value, effectively resetting the auto-incrementing sequence.
Q10
True / FalseWhen migrating from MySQL to PostgreSQL, you can directly map MySQL's AUTO_INCREMENT to PostgreSQL's SERIAL without any issues.
While MySQL's AUTO_INCREMENT can be mapped to PostgreSQL's SERIAL, there are differences in behavior and syntax that need to be considered during migration. For example, sequence handling and default values need to be explicitly managed in PostgreSQL.
Q21
Multiple ChoiceWhich 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)
);
This command creates an 'employees' table where the 'employee_id' column is automatically incremented using the SERIAL data type, which is a shorthand for creating an auto-incrementing integer column.
Q22
Multiple ChoiceWhich 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
);
This command creates an 'orders' table where the 'order_id' column is automatically incremented using the IDENTITY keyword, which is a more flexible alternative to SERIAL.
Q24
Multiple ChoiceWhich 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
);
This command creates a 'transactions' table where the 'transaction_id' column is automatically incremented using the BIGSERIAL data type, which is used for larger integer ranges.
Q25
Multiple ChoiceWhich 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)
);
This command creates an 'invoices' table where the 'invoice_id' column is automatically incremented using the GENERATED BY DEFAULT AS IDENTITY option, allowing manual inserts if needed.
Q30
Multiple ChoiceWhich 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
);
This command creates a 'logs' table where the 'log_id' column starts incrementing from 1000000 using the BIGINT data type and the IDENTITY keyword.