Complete the code to create a table with a column that has a default value of 100.
CREATE TABLE products (id SERIAL PRIMARY KEY, stock INTEGER DEFAULT [1]);The DEFAULT value should be a number without quotes for an integer column.
Complete the code to set the default value of a timestamp column to the current time.
CREATE TABLE events (id SERIAL PRIMARY KEY, created_at TIMESTAMP DEFAULT [1]);NOW() returns the current date and time, suitable for a TIMESTAMP default.
Fix the error in the code to set a default value for a column that stores the current year.
CREATE TABLE reports (id SERIAL PRIMARY KEY, year INTEGER DEFAULT [1]);PostgreSQL uses EXTRACT(YEAR FROM timestamp) to get the year as a number.
Fill both blanks to create a table where a column has a default value of the current date plus 7 days.
CREATE TABLE tasks (id SERIAL PRIMARY KEY, due_date DATE DEFAULT [1] + INTERVAL '[2]');
CURRENT_DATE returns today's date, and adding INTERVAL '7 day' adds 7 days to it.
Fill all three blanks to create a table with a column that defaults to the uppercase username or 'GUEST' if none is provided.
CREATE TABLE users (id SERIAL PRIMARY KEY, username TEXT DEFAULT COALESCE(UPPER([1]), [2]) [3]);
COALESCE returns the uppercase username or 'GUEST' if username is NULL. The column allows NULLs.