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;
Think about how schema-qualified names work in PostgreSQL.
When you specify a schema name before a table, PostgreSQL queries that specific table only. So sales.employees refers to the employees table inside the sales schema.
What is the main purpose of using schemas in PostgreSQL?
Think about why you might want to have multiple tables with the same name in one database.
Schemas allow grouping tables and other objects into separate namespaces. This helps avoid name clashes and organize objects logically.
Which of the following commands correctly creates a schema named marketing and sets it as the first schema in the search path?
Remember the syntax for setting the search path and the order of schemas matters.
The command SET search_path TO marketing, public; sets the search path so that PostgreSQL looks first in the marketing schema, then public. The keyword TO is correct syntax.
You have a large database with many tables. How can using schemas help optimize database management and queries?
Think about administrative tasks and security.
Schemas help organize tables logically, making it easier to assign permissions and manage backups per group. They do not automatically partition or compress data.
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?
Think about how to tell PostgreSQL exactly which table you want.
Explicitly specifying the schema removes ambiguity. Renaming or dropping tables is not always practical. Setting search_path might help but can still cause ambiguity if both schemas are in the path.