Skip to main content
The REASSIGN OWNED statement changes the ownership of all database objects (i.e., tables, types, or schemas) in the current database that are currently owned by a specific role or user. The REASSIGN OWNED statement performs a schema change. For more information about how online schema changes work in CockroachDB, see Online Schema Changes.
To change the ownership of any single object (e.g., a table or a database), use the OWNER TO subcommand of the object’s ALTER statement.

Required privileges

  • To reassign ownership with REASSIGN OWNED, the user must be a member of the current owner’s role and a member of the target owner’s role.
  • Members of the admin role can always use REASSIGN OWNED BY.

Syntax

reassign_owned_by syntax diagram

Parameters

Example

Setup

To follow along, run cockroach demo to start a temporary, in-memory cluster with the movr sample dataset preloaded:

Change the owner of all tables in a database

Suppose that the current owner of the users, vehicles, and rides tables in the movr database is a role named cockroachlabs.
Now suppose you want to change the owner for all of the tables owned by cockroachlabs to a new role named movrlabs.

See also