# DATABASE

## Syntax

```sql
DATABASE()
SCHEMA()
```

## Description

Returns the default (current) database name as a string in the utf8 [character set](https://mariadb.com/docs/server/reference/data-types/string-data-types/character-sets). If there is no default database, `DATABASE()` returns `NULL`. Within a [stored routine](https://mariadb.com/docs/server/server-usage/stored-routines), the default database is the database that the routine is associated with, which is not necessarily the same as the database that is the default in the calling context.

`SCHEMA()` is a synonym for `DATABASE()`.

To select a default database, the [USE](https://mariadb.com/docs/server/reference/sql-statements/administrative-sql-statements/use-database) statement can be run. Another way to set the default database is specifying its name at [mariadb](https://mariadb.com/docs/server/clients-and-utilities/mariadb-client/mariadb-command-line-client) command line client startup.

## Examples

```sql
SELECT DATABASE();
+------------+
| DATABASE() |
+------------+
| NULL       |
+------------+

USE test;
Database changed

SELECT DATABASE();
+------------+
| DATABASE() |
+------------+
| test       |
+------------+
```

<sub>*This page is licensed: GPLv2, originally from*</sub> [<sub>*fill\_help\_tables.sql*</sub>](https://github.com/MariaDB/server/blob/main/scripts/fill_help_tables.sql)

{% @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-functions/secondary-functions/information-functions/database.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.
