0
0
PostgreSQLquery~10 mins

Serial and identity columns in PostgreSQL - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a table with a serial primary key column.

PostgreSQL
CREATE TABLE users (id [1] PRIMARY KEY, name VARCHAR(100));
Drag options to blanks, or click blank then click option'
AINTEGER
BTEXT
CSERIAL
DBOOLEAN
Attempts:
3 left
💡 Hint
Common Mistakes
Using INTEGER without auto-increment will require manual value insertion.
Using TEXT or BOOLEAN types for primary keys is not appropriate.
2fill in blank
medium

Complete the code to define an identity column that auto-generates values starting from 1.

PostgreSQL
CREATE TABLE orders (order_id INT GENERATED ALWAYS AS IDENTITY (START WITH [1]), order_date DATE);
Drag options to blanks, or click blank then click option'
A0
B100
CNULL
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Starting identity columns at 0 may cause confusion or errors.
Using NULL as a start value is invalid.
3fill in blank
hard

Fix the error in the code to correctly create a serial column named 'product_id'.

PostgreSQL
CREATE TABLE products (product_id [1] PRIMARY KEY, name TEXT);
Drag options to blanks, or click blank then click option'
ASERIAL
BSERIAL PRIMARY
CSERIAL PRIMARY KEY
DINTEGER SERIAL
Attempts:
3 left
💡 Hint
Common Mistakes
Adding 'PRIMARY' inside the type causes syntax errors.
Using 'INTEGER SERIAL' is invalid syntax.
4fill in blank
hard

Fill both blanks to create a table with an identity column that increments by 5 starting at 10.

PostgreSQL
CREATE TABLE invoices (invoice_id INT GENERATED [1] AS IDENTITY (START WITH [2], INCREMENT BY 5));
Drag options to blanks, or click blank then click option'
AALWAYS
BBY DEFAULT
C10
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'BY DEFAULT' when 'ALWAYS' is required.
Starting at 1 instead of 10.
5fill in blank
hard

Fill all three blanks to create a table with a serial column and a name column with a default value.

PostgreSQL
CREATE TABLE employees (emp_id [1] PRIMARY KEY, name VARCHAR(50) DEFAULT [2], hired_date DATE DEFAULT [3]);
Drag options to blanks, or click blank then click option'
ASERIAL
B'Unknown'
CCURRENT_DATE
DINTEGER
Attempts:
3 left
💡 Hint
Common Mistakes
Using INTEGER instead of SERIAL for auto-increment.
Missing quotes around default string values.
Using wrong default for date column.