0
0
PostgreSQLquery~30 mins

Creating and switching schemas in PostgreSQL - Try It Yourself

Choose your learning style9 modes available
Creating and Switching Schemas in PostgreSQL
📖 Scenario: You are managing a PostgreSQL database for a small company. You want to organize data by creating separate schemas for different departments. This helps keep data tidy and easy to find.
🎯 Goal: Learn how to create a new schema and switch to it so you can create tables inside that schema.
📋 What You'll Learn
Create a new schema named sales
Switch the current schema search path to sales
Create a table named customers inside the sales schema
The customers table should have columns id (integer) and name (text)
💡 Why This Matters
🌍 Real World
Organizing database objects into schemas helps keep data separated by department or function, making management easier.
💼 Career
Database administrators and developers often create and switch schemas to manage complex databases efficiently.
Progress0 / 4 steps
1
Create the sales schema
Write a SQL statement to create a new schema called sales.
PostgreSQL
Need a hint?

Use the CREATE SCHEMA command followed by the schema name.

2
Switch to the sales schema
Write a SQL statement to set the search path to the sales schema so that new tables will be created there by default.
PostgreSQL
Need a hint?

Use the SET search_path TO command with the schema name.

3
Create the customers table in sales
Write a SQL statement to create a table named customers with columns id as integer and name as text. This table should be created inside the current schema, which is sales.
PostgreSQL
Need a hint?

Use CREATE TABLE customers (id INTEGER, name TEXT); to create the table.

4
Verify the current schema search path
Write a SQL statement to show the current schema search path to confirm it is set to sales.
PostgreSQL
Need a hint?

Use the SHOW search_path; command to display the current schema search path.