Complete the code to create a table with an auto-incrementing primary key.
CREATE TABLE users (id INT [1] PRIMARY KEY, name VARCHAR(50));
The AUTO_INCREMENT keyword makes the id column automatically increase with each new row.
Complete the code to insert a new user without specifying the auto-increment column.
INSERT INTO users (name) VALUES ([1]);When inserting, you only provide the name. The id is generated automatically.
Fix the error in the code to reset the auto-increment counter to 1.
ALTER TABLE users [1] = 1;
The correct syntax to reset the auto-increment value is to set AUTO_INCREMENT to 1.
Fill both blanks to create a table where the auto-increment starts at 1000.
CREATE TABLE orders (order_id INT [1] PRIMARY KEY) [2];
The AUTO_INCREMENT keyword defines the column, and AUTO_INCREMENT=1000 sets the starting value for the table.
Fill in the blanks to select the next auto-increment value, insert a new row, and then get the last inserted id.
SELECT [1] FROM information_schema.tables WHERE table_name = 'users'; INSERT INTO users (name) VALUES ('Bob'); SELECT [2]();
The first query gets the next auto-increment value. The last query gets the id of the last inserted row using LAST_INSERT_ID().