# SET ROLE

## Syntax

```
SET ROLE { role | NONE }
```

## Description

{% hint style="info" %}
Only one role can be current at a time. Executing `SET ROLE` replaces the current role; it does not add to a list of current roles. This is SQL Standard compliant behavior which differs from MySQL, where you may have several current roles at a time.
{% endhint %}

The `SET ROLE` statement switches the current role for the session, enabling its associated permissions. To have no current role, set `NONE`.

If a role that doesn't exist, or to which the user has not been assigned, is specified, an `ERROR 1959 (OP000): Invalid role specification` error occurs.

An automatic SET ROLE is implicitly performed when a user connects if that user has been assigned a default role. See [SET DEFAULT ROLE](https://mariadb.com/docs/server/reference/sql-statements/account-management-sql-statements/set-default-role).

## Example

```sql
--Checking the current role status
SELECT CURRENT_ROLE;
```

{% code title="No role active" %}

```
+--------------+
| CURRENT_ROLE |
+--------------+
| NULL         |
+--------------+
```

{% endcode %}

```sql
--Setting the staff role, and verifying the switch
SET ROLE staff;
SELECT CURRENT_ROLE;
```

{% code title="" %}

```
+--------------+
| CURRENT_ROLE |
+--------------+
| staff        |
+--------------+
```

{% endcode %}

```sql
--switching to 'admin' role, and verifying the switch
SET ROLE admin;
SELECT CURRENT_ROLE;
```

{% code title="" %}

```
+--------------+
| CURRENT_ROLE |
+--------------+
| admin        |
+--------------+
```

{% endcode %}

```sql
--Removing the active role
SET ROLE NONE;
SELECT CURRENT_ROLE();
```

```
+----------------+
| CURRENT_ROLE() |
+----------------+
| NULL           |
+----------------+
```

<sub>*This page is licensed: CC BY-SA / Gnu FDL*</sub>

{% @marketo/form formId="4316" %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://mariadb.com/docs/server/reference/sql-statements/account-management-sql-statements/set-role.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
