0
0
PostgreSQLquery~20 mins

Schemas for namespace organization in PostgreSQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Schema Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
Querying tables in different schemas

Consider two schemas sales and hr in a PostgreSQL database. Each schema has a table named employees. What will the following query return?

SELECT * FROM sales.employees;
AAll rows from the employees table in the sales schema
BAll rows from the employees table in the hr schema
CAll rows from employees tables in both sales and hr schemas combined
DAn error because employees table exists in multiple schemas
Attempts:
2 left
💡 Hint

Think about how schema-qualified names work in PostgreSQL.

🧠 Conceptual
intermediate
1:30remaining
Purpose of schemas in PostgreSQL

What is the main purpose of using schemas in PostgreSQL?

ATo improve query performance by indexing tables automatically
BTo encrypt data stored in tables
CTo organize database objects into separate namespaces to avoid name conflicts
DTo automatically backup tables daily
Attempts:
2 left
💡 Hint

Think about why you might want to have multiple tables with the same name in one database.

📝 Syntax
advanced
2:00remaining
Creating a schema and setting search path

Which of the following commands correctly creates a schema named marketing and sets it as the first schema in the search path?

ACREATE SCHEMA marketing; SET search_path TO marketing, public;
BCREATE SCHEMA marketing; SET search_path = marketing, public;
CCREATE SCHEMA marketing; SET search_path TO public, marketing;
DCREATE SCHEMA marketing; SET search_path = public, marketing;
Attempts:
2 left
💡 Hint

Remember the syntax for setting the search path and the order of schemas matters.

optimization
advanced
2:30remaining
Optimizing schema usage for large databases

You have a large database with many tables. How can using schemas help optimize database management and queries?

ASchemas automatically partition tables to improve query speed
BBy grouping related tables into schemas, you can manage permissions and backups more efficiently
CSchemas compress data to reduce storage size
DSchemas replicate tables across servers for load balancing
Attempts:
2 left
💡 Hint

Think about administrative tasks and security.

🔧 Debug
expert
3:00remaining
Resolving ambiguous table reference error

You run the query SELECT * FROM employees; but get an error saying the table reference is ambiguous. You have two schemas, sales and hr, each with an employees table. How can you fix this error?

ASet the search_path to only one schema containing employees table
BRename one of the employees tables to a different name
CDrop one of the employees tables
DSpecify the schema explicitly in the query, e.g., <code>SELECT * FROM sales.employees;</code>
Attempts:
2 left
💡 Hint

Think about how to tell PostgreSQL exactly which table you want.