Which statement correctly describes the difference between AUTO_INCREMENT in MySQL and SERIAL in PostgreSQL?
Think about how each database handles automatic numbering internally.
In MySQL, AUTO_INCREMENT is a column attribute that automatically increments numeric values. In PostgreSQL, SERIAL is a pseudo-type that creates an integer column, a sequence, and sets the default value to the next sequence number.
Given the following SQL Server table and insert statements, what will be the output of the SELECT * FROM Employees; query?
CREATE TABLE Employees (
ID INT IDENTITY(1,1) PRIMARY KEY,
Name VARCHAR(50)
);
INSERT INTO Employees (Name) VALUES ('Alice');
INSERT INTO Employees (Name) VALUES ('Bob');
Remember how IDENTITY columns auto-increment starting from the seed value.
The IDENTITY(1,1) means the first value is 1 and increments by 1 for each new row. So Alice gets ID 1, Bob gets ID 2.
Which of the following SQL statements correctly creates a table with a SERIAL primary key column in PostgreSQL?
Check the correct placement of PRIMARY KEY and the data type.
Option B uses id SERIAL PRIMARY KEY which is the correct syntax. Option B wrongly adds INT before SERIAL. Option B sets username as primary key, not id. Option B uses invalid keyword PRIMARY.
You are designing a high-traffic web application using PostgreSQL. Which auto-increment method is best to avoid contention and ensure fast inserts?
Consider modern PostgreSQL features designed for concurrency.
PostgreSQL 10+ supports IDENTITY columns which are standard-compliant and better optimized for concurrency than SERIAL. AUTO_INCREMENT is not supported in PostgreSQL.
Consider this MySQL table and insert statements:
CREATE TABLE orders ( order_id INT AUTO_INCREMENT PRIMARY KEY, product VARCHAR(50) ); INSERT INTO orders (order_id, product) VALUES (NULL, 'Book'); INSERT INTO orders (order_id, product) VALUES (5, 'Pen'); INSERT INTO orders (order_id, product) VALUES (NULL, 'Notebook');
After these inserts, what will be the order_id values in the table?
Remember how MySQL handles explicit values and NULL with AUTO_INCREMENT.
First insert with NULL gets order_id 1. Second insert explicitly sets order_id 5. Third insert with NULL gets next auto-increment value after 5, which is 6.