SQL Server
CREATE SCHEMA sales AUTHORIZATION dbo;
Must be the only statement in its batch. Objects are addressed as sales.orders, and each user's default schema (usually dbo) resolves unqualified names.
Namespaces for tables: schemas, or whatever each engine calls the idea.
Filed under Tables & schema
PostgreSQL and SQL Server use schemas as everyday namespaces; Oracle has them too but ties each to a user; MySQL's schema is the database; SQLite replaces the idea with attached files.
PostgreSQL, SQL Server and Oracle have schemas as named namespaces inside one database; in Oracle a schema is what a user owns. MySQL treats schema and database as the same thing. SQLite has no schemas inside a file; attaching another database file under a name is the closest equivalent.
CREATE SCHEMA sales AUTHORIZATION dbo;
Must be the only statement in its batch. Objects are addressed as sales.orders, and each user's default schema (usually dbo) resolves unqualified names.
CREATE SCHEMA sales;
search_path decides how unqualified names resolve. CREATE SCHEMA IF NOT EXISTS keeps migration scripts rerunnable.
CREATE DATABASE sales;
CREATE SCHEMA sales means exactly the same. A database is the only namespace level, and queries can join across databases on the same server.
ATTACH DATABASE 'sales.db' AS sales;
Opens (or creates) another file and names it; qualify tables as sales.orders. The built-in names are main and temp. DETACH DATABASE sales closes it.
CREATE USER sales IDENTIFIED BY sales_pwd QUOTA 100M ON users;
Creating the user creates the schema of the same name. 18c+ also offers schema-only accounts with NO AUTHENTICATION, which own objects but can't log in. Grant CREATE TABLE before it can hold objects.
Each Oracle user owns exactly one schema with the same name, and objects are created in it. Other schemas' objects are reached as sales.orders after a GRANT, and synonyms can hide the prefix. 23ai adds schema-level privileges such as GRANT SELECT ANY TABLE ON SCHEMA sales.
A database is a separate connection target with its own catalogs; schemas are namespaces inside it. Queries across schemas are plain SQL, while queries across databases need postgres_fdw or dblink.
Attached databases. Each connection can attach up to 10 files by default (the compile-time maximum is 125), and a single query can join tables across them by name, with transactions covering all of them.
Point a new name at the same table, and swap two tables' names without a gap.
Scratch tables only your session can see, for staging, deduplication and multi-step queries.
Store documentation with the schema so tools and later readers can find it.
SQLly is a native SQL workbench for macOS, Windows and Linux. Its formatter and plan viewer work in all five dialects.