> ## Documentation Index
> Fetch the complete documentation index at: /documents/llms.txt
> Use this file to discover all available pages before exploring further.

# SET ROLE

> SET ROLE activates roles, along with all of its associated privileges and nested roles, for the current session.

SET ROLE activates roles, along with all of its associated privileges and nested roles, for the current session. After the role is activated, users can use this role to perform operations.

After running this command, you can run `select is_role_in_session("<role_name>");` to verify whether this role is active in the current session.

This command is supported from v3.0.

## Usage notes

Users can only activate roles that have been assigned to them.

You can query the roles of a user using [SHOW GRANTS](/documents/4.2/sql-reference/sql-statements/account-management/SHOW_GRANTS.md).

You can query the active roles of the current user using `SELECT CURRENT_ROLE()`. For more information, see [current\_role](/documents/4.2/sql-reference/sql-functions/utility-functions/current_role.md).

The activated role affects all authorization checks, including queries against `information_schema` system views. For example, after executing `SET ROLE role1`, queries like `SELECT * FROM information_schema.tables` will only return tables accessible through `role1`. This ensures that role-based access control is consistently applied across all system catalogs and metadata queries.

## Syntax

```SQL theme={null}
-- Active specific roles and perform operations as this role.
SET ROLE <role_name>[,<role_name>,..];
-- Activate all roles of a user, except for specific roles.
SET ROLE ALL EXCEPT <role_name>[,<role_name>,..]; 
-- Activate all roles of a user.
SET ROLE ALL;
```

## Parameters

`role_name`: the role name

## Examples

Query all the roles of the current user.

```SQL theme={null}
SHOW GRANTS;
+--------------+---------+----------------------------------------------+
| UserIdentity | Catalog | Grants                                       |
+--------------+---------+----------------------------------------------+
| 'test'@'%'   | NULL    | GRANT 'db_admin', 'user_admin' TO 'test'@'%' |
+--------------+---------+----------------------------------------------+
```

Activate the `db_admin` role.

```SQL theme={null}
SET ROLE db_admin;
```

Query active roles of the current user.

```SQL theme={null}
SELECT CURRENT_ROLE();
+--------------------+
| CURRENT_ROLE()     |
+--------------------+
| db_admin           |
+--------------------+
```

## References

* [CREATE ROLE](/documents/4.2/sql-reference/sql-statements/account-management/CREATE_ROLE.md): creates a role.
* [GRANT](/documents/4.2/sql-reference/sql-statements/account-management/GRANT.md): assigns roles to users or other roles.
* [ALTER USER](/documents/4.2/sql-reference/sql-statements/account-management/ALTER_USER.md): modifies roles.
* [SHOW ROLES](/documents/4.2/sql-reference/sql-statements/account-management/SHOW_ROLES.md): show all roles in the system.
* [current\_role](/documents/4.2/sql-reference/sql-functions/utility-functions/current_role.md): show roles of the current user.
* [is\_role\_in\_session](/documents/4.2/sql-reference/sql-functions/utility-functions/is_role_in_session.md): verifies whether a role (or a nested role) is active in the current session.
* [DROP ROLE](/documents/4.2/sql-reference/sql-statements/account-management/DROP_ROLE.md): drops a role.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.