Complete the code to create a table with an auto-incrementing primary key.
CREATE TABLE users (id [1] PRIMARY KEY, name VARCHAR(100));
The SERIAL keyword creates an auto-incrementing integer column, perfect for primary keys.
Complete the code to insert a new user without specifying the primary key value.
INSERT INTO users (name) VALUES ([1]);When the primary key is SERIAL, you don't specify it in the insert; just provide the other columns.
Fix the error in the code to create a table with a primary key that auto-increments.
CREATE TABLE orders (order_id [1] PRIMARY KEY, order_date DATE);Using SERIAL for order_id ensures it auto-increments and can be a primary key.
Fill both blanks to create a table with a primary key that auto-increments and a unique username.
CREATE TABLE accounts (id [1] PRIMARY KEY, username [2] UNIQUE);
The id uses SERIAL for auto-incrementing primary key. The username uses VARCHAR with UNIQUE constraint.
Fill all three blanks to insert a new account with a username, letting the id auto-increment.
INSERT INTO accounts (id, username) VALUES ([1], [2]); -- Use [3] for id to auto-increment
Use DEFAULT for id to let it auto-increment. Provide the username as a string.