0
0
SQLquery~20 mins

AUTO_INCREMENT vs SERIAL vs IDENTITY in SQL - Practice Questions

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Auto-Increment Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Difference between AUTO_INCREMENT and SERIAL

Which statement correctly describes the difference between AUTO_INCREMENT in MySQL and SERIAL in PostgreSQL?

AAUTO_INCREMENT is a column attribute in MySQL, while SERIAL is a pseudo-type in PostgreSQL that creates a sequence and sets a default value.
BAUTO_INCREMENT and SERIAL are identical and interchangeable in all SQL databases.
CAUTO_INCREMENT requires manual sequence creation, but SERIAL automatically increments without sequences.
DSERIAL is used only for string columns, while AUTO_INCREMENT is for numeric columns.
Attempts:
2 left
💡 Hint

Think about how each database handles automatic numbering internally.

query_result
intermediate
2:00remaining
Output of IDENTITY column insertion

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');
A
ID | Name
1  | Alice
2  | Bob
B
ID | Name
0  | Alice
1  | Bob
C
ID | Name
1  | Alice
1  | Bob
D
ID | Name
NULL | Alice
NULL | Bob
Attempts:
2 left
💡 Hint

Remember how IDENTITY columns auto-increment starting from the seed value.

📝 Syntax
advanced
2:00remaining
Correct syntax for SERIAL column in PostgreSQL

Which of the following SQL statements correctly creates a table with a SERIAL primary key column in PostgreSQL?

ACREATE TABLE users (id INT SERIAL PRIMARY KEY, username VARCHAR(50));
BCREATE TABLE users (id SERIAL PRIMARY KEY, username VARCHAR(50));
CCREATE TABLE users (id SERIAL, username VARCHAR(50) PRIMARY KEY);
DCREATE TABLE users (id SERIAL PRIMARY, username VARCHAR(50));
Attempts:
2 left
💡 Hint

Check the correct placement of PRIMARY KEY and the data type.

optimization
advanced
2:00remaining
Choosing the best auto-increment method for high concurrency

You are designing a high-traffic web application using PostgreSQL. Which auto-increment method is best to avoid contention and ensure fast inserts?

AUse <code>SERIAL</code> columns with default sequences.
BUse <code>AUTO_INCREMENT</code> attribute as in MySQL.
CUse <code>IDENTITY</code> columns introduced in PostgreSQL 10+.
DManually create a sequence and use <code>nextval()</code> in insert statements.
Attempts:
2 left
💡 Hint

Consider modern PostgreSQL features designed for concurrency.

🔧 Debug
expert
3:00remaining
Why does this MySQL AUTO_INCREMENT insert fail?

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?

ANULL, 5, NULL
B1, 6, 7
C1, 1, 2
D1, 5, 6
Attempts:
2 left
💡 Hint

Remember how MySQL handles explicit values and NULL with AUTO_INCREMENT.