SQL Keywords

SQL OWNER

What does the SQL OWNER clause do?

Changes or sets the owning role of a database object so that the specified role becomes its new owner.
Sign up to get up to date news on SQL keywords
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.

Compatible dialects for SQL OWNER: PostgreSQL, Amazon Redshift, Greenplum, YugabyteDB, CockroachDB, Snowflake (similar syntax), IBM Db2 (ALTER ... OWNER), not available in MySQL or SQLite; SQL Server uses ALTER AUTHORIZATION instead.

SQL OWNER Full Explanation

OWNER is not a standalone SQL statement but a clause used in several PostgreSQL commands (and dialects derived from it) to assign or transfer ownership of a database object to a different role. Ownership implies full privilege over an object and the right to grant privileges to others. Common commands that include OWNER are ALTER TABLE, ALTER VIEW, ALTER SEQUENCE, ALTER DATABASE, ALTER FUNCTION, CREATE SCHEMA, and CREATE DATABASE. Only a superuser or the current owner can change an object’s owner. When ownership changes, any default privileges tied to the old owner remain unchanged unless explicitly re-granted. Some objects (for example, system catalogs) cannot have their owner changed.

SQL OWNER Syntax

ALTER TABLE object_name
  OWNER TO new_owner;

-- Other common variants
ALTER DATABASE db_name OWNER TO new_owner;
ALTER SEQUENCE seq_name OWNER TO new_owner;
CREATE SCHEMA schema_name AUTHORIZATION owner_name;

SQL OWNER Parameters

  • object_name (identifier) - Name of the table, view, sequence, or other object whose ownership is being changed
  • new_owner (role name) - Target role that will become the new owner

Example Queries Using SQL OWNER

-- Transfer a table to the analytics role
ALTER TABLE public.pageviews OWNER TO analytics;

-- Change database owner
ALTER DATABASE reporting OWNER TO data_eng;

-- Create a schema owned by a service account
CREATE SCHEMA logs AUTHORIZATION svc_logging;

Expected Output Using SQL OWNER

  • Ownership of the specified object is transferred
  • The new owner automatically gains all privileges that ownership confers
  • No result set is returned; the server replies with ALTER TABLE, ALTER DATABASE, etc

Use Cases with SQL OWNER

  • Handing off an object from a personal role to a team role before production use
  • Standardizing ownership so automated jobs (ETL, CI pipelines) run under service accounts
  • Cleaning up after importing a dump that set every object owner to the superuser
  • Preparing objects for handover to another department during re-organisation

Common Mistakes with SQL OWNER

  • Trying to change owner without being the current owner or a superuser (results in permission denied)
  • Forgetting to update dependent objects whose privileges rely on the old owner
  • Assuming OWNER is a separate statement rather than a clause inside ALTER or CREATE commands
  • Omitting the TO keyword (syntax error)

Related Topics

ALTER TABLE, ALTER DATABASE, GRANT, REVOKE, CREATE SCHEMA, ROLE, PRIVILEGES

First Introduced In

PostgreSQL 7.3

Frequently Asked Questions

Who can execute ALTER ... OWNER TO?

The command can be executed by the current owner of the object or by a superuser. Regular roles without ownership cannot transfer ownership.

Does changing the owner affect existing GRANTs?

No. Any explicit GRANTs remain unchanged. The new owner automatically has full rights; the old owner loses implicit rights but keeps any separate GRANTed privileges.

Is OWNER a standard SQL keyword?

OWNER is PostgreSQL specific. Other systems like SQL Server use ALTER AUTHORIZATION, while MySQL lacks an equivalent command.

How can I bulk change owners for all tables in a schema?

Generate ALTER TABLE statements via psql meta-commands or a DO block that loops through pg_class entries, then run them in a single transaction.

Sign up to get up to date news on SQL keywords
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.
Trusted by top engineers on high-velocity teams
Aryeo Logo
Assort Health
Curri
Rubie Logo
Bauhealth Logo
Truvideo Logo

Check out other commonly used SQL Keywords!