Challenge - 5 Problems
Schema Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
What is the output of this schema creation query?
Consider the following SQL commands executed in PostgreSQL:
What will be the result of the SELECT query?
CREATE SCHEMA sales;
CREATE TABLE sales.orders (id SERIAL PRIMARY KEY, amount INT);
SELECT * FROM sales.orders;
What will be the result of the SELECT query?
PostgreSQL
CREATE SCHEMA sales; CREATE TABLE sales.orders (id SERIAL PRIMARY KEY, amount INT); SELECT * FROM sales.orders;
Attempts:
2 left
💡 Hint
Think about what happens when you create a new table and select from it without inserting data.
✗ Incorrect
The table sales.orders is created empty. Selecting from it returns zero rows but shows the columns defined.
❓ query_result
intermediate2:00remaining
What is the current schema after SET search_path?
Given these commands:
What will the SHOW search_path command output?
CREATE SCHEMA marketing;
SET search_path TO marketing, public;
SHOW search_path;
What will the SHOW search_path command output?
PostgreSQL
CREATE SCHEMA marketing; SET search_path TO marketing, public; SHOW search_path;
Attempts:
2 left
💡 Hint
The SET search_path command sets the order of schemas PostgreSQL looks into.
✗ Incorrect
The search_path is set to 'marketing, public' so SHOW search_path returns that exact string.
📝 Syntax
advanced2:00remaining
Which option correctly creates a schema and switches to it?
Which of the following SQL command sequences correctly creates a schema named 'archive' and sets it as the current schema for subsequent commands?
Attempts:
2 left
💡 Hint
PostgreSQL uses search_path to control schema lookup, not USE or SWITCH TO.
✗ Incorrect
In PostgreSQL, USE and SWITCH TO are not valid commands. The correct way to change schema context is SET search_path.
🔧 Debug
advanced2:00remaining
Why does this query fail after creating a schema?
A user runs these commands:
The SELECT query fails with "relation \"data\" does not exist". Why?
CREATE SCHEMA reports;
CREATE TABLE reports.data (id INT);
SELECT * FROM data;
The SELECT query fails with "relation \"data\" does not exist". Why?
PostgreSQL
CREATE SCHEMA reports; CREATE TABLE reports.data (id INT); SELECT * FROM data;
Attempts:
2 left
💡 Hint
Think about how PostgreSQL finds tables without schema prefix.
✗ Incorrect
Without setting search_path to include 'reports', PostgreSQL looks only in 'public' by default and cannot find 'data'.
🧠 Conceptual
expert2:00remaining
What is the effect of setting search_path to "$user", public?
In PostgreSQL, what does setting
search_path to "$user", public do?Attempts:
2 left
💡 Hint
"$user" is a special placeholder in PostgreSQL search_path.
✗ Incorrect
The "$user" placeholder is replaced by the current database user name, so PostgreSQL searches that schema first, then public.