Complete the code to create a table with a serial primary key column.
CREATE TABLE users (id [1] PRIMARY KEY, name VARCHAR(100));
The SERIAL keyword automatically creates an integer column that auto-increments with each new row, perfect for primary keys.
Complete the code to define an identity column that auto-generates values starting from 1.
CREATE TABLE orders (order_id INT GENERATED ALWAYS AS IDENTITY (START WITH [1]), order_date DATE);The START WITH 1 clause sets the first generated value to 1 for the identity column.
Fix the error in the code to correctly create a serial column named 'product_id'.
CREATE TABLE products (product_id [1] PRIMARY KEY, name TEXT);The correct syntax is to use SERIAL for the column type and specify PRIMARY KEY separately. The code already has PRIMARY KEY after the blank, so just SERIAL is needed.
Fill both blanks to create a table with an identity column that increments by 5 starting at 10.
CREATE TABLE invoices (invoice_id INT GENERATED [1] AS IDENTITY (START WITH [2], INCREMENT BY 5));
GENERATED ALWAYS AS IDENTITY ensures the database always generates the value. START WITH 10 sets the first value to 10, and INCREMENT BY 5 increases by 5 each time.
Fill all three blanks to create a table with a serial column and a name column with a default value.
CREATE TABLE employees (emp_id [1] PRIMARY KEY, name VARCHAR(50) DEFAULT [2], hired_date DATE DEFAULT [3]);
SERIAL creates an auto-incrementing primary key. The name column defaults to the string 'Unknown' if no name is given. The hired_date column defaults to the current date.