DROP OWNED BY statement drops all objects owned by and any grants on objects not owned by a role.
The
DROP OWNED BY statement performs a schema change. For more information about how online schema changes work in CockroachDB, see Online Schema Changes.Required privileges
The role must have theDROP privilege on the specified objects.
DROP OWNED BY will result in an error if the user was granted a system-level privilege (i.e., using the GRANT SYSTEM ... statement). To work around this, use SHOW SYSTEM GRANTS FOR <role> and then use REVOKE SYSTEM ... for each system-level privilege in the result.
Synopsis
Parameters
Known limitations
- Enum types are not dropped.
-
If the role for which you are trying to
DROP OWNED BYwas granted a system-level privilege (i.e., using theGRANT SYSTEM ...statement), the error shown below will be signalled. The workaround is to useSHOW SYSTEM GRANTS FOR {role}and then useREVOKE SYSTEM ...for each privilege in the result.
Examples
The following examples assume a local cluster is running. They involve a user we will create calledmaxroach and several tables. The setup is shown below.
From a Terminal window, open a SQL shell as the root user:
maxroach:
maxroach.
Drop all objects owned by a user/role
From themaxroach user’s SQL shell, create a table called max_kv:
maxroach, use SHOW GRANTS:
maxroach, switch to the root user’s SQL shell and use DROP OWNED BY:
maxroach only owns the max_kv table, so this will drop that table from the database completely. To confirm that the table has been dropped, run SHOW TABLES:
root user’s SQL shell, use SHOW GRANTS to further confirm that the maxroach user has no remaining object grants:
Drop all grants on objects for a user/role
From theroot user’s SQL shell, create a table called root_kv:
maxroach using GRANT ALL:
maxroach has all privileges on the table using SHOW GRANTS:
maxroach user’s SQL shell, and insert some data into the table. It should succeed:
root user’s SQL shell and use DROP OWNED BY to remove all grants on objects to the user maxroach:
maxroach has no grants on any objects using SHOW GRANTS:
maxroach user’s SQL shell and try to insert data into the root_kv table. This should signal an error:

